MaelstromTools Dev CCE

C&C Tiberium Alliances - Just a set of statistics & summaries about repair time and base resources. Mainly for internal use, but you are free to test and comment it.

目前为 2018-01-27 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name MaelstromTools Dev CCE
  3. // @namespace MaelstromTools
  4. // @description C&C Tiberium Alliances - Just a set of statistics & summaries about repair time and base resources. Mainly for internal use, but you are free to test and comment it.
  5. // @version 0.1.4.48 - cce
  6. // @author Maelstrom, HuffyLuf, KRS_L, Krisan and DLwarez, Chillchef
  7. // @include http*://prodgame*.alliances.commandandconquer.com/*/index.aspx*
  8. // ==/UserScript==
  9.  
  10. (function () {
  11. var MaelstromTools_main = function () {
  12. try {
  13. function CCTAWrapperIsInstalled() {
  14. return (typeof (CCTAWrapper_IsInstalled) != 'undefined' && CCTAWrapper_IsInstalled);
  15. }
  16.  
  17. function createMaelstromTools() {
  18. console.log('MaelstromTools loaded');
  19.  
  20. qx.Class.define("MaelstromTools.Language", {
  21. type: "singleton",
  22. extend: qx.core.Object,
  23. construct: function (language) {
  24. this.Languages = ['de_DE', 'pt_PT', 'fr_FR', 'tr_TR']; // en is default, not needed in here!
  25. if (language != null) {
  26. this.MyLanguage = language;
  27. }
  28. },
  29. members: {
  30. MyLanguage: "en",
  31. Languages: null,
  32. Data: null,
  33.  
  34. loadData: function (language) {
  35. //var l = this.Languages.indexOf(language);
  36. var l = 0;
  37. if (l < 0) {
  38. this.Data = null;
  39. return;
  40. }
  41. // upgrade-übersicht: UpgradePriorityGUI Z2730
  42. // produktion-übersicht : qx.Class.define("MaelstromTools.Production" Z1295
  43. this.Data = {};
  44. this.Data["Collect all packages"] = ["Alle Pakete einsammeln", "Recolher todos os pacotes", "Récupérez tous les paquets", "Tüm paketleri topla"][l];
  45. this.Data["Overall production"] = ["Produktionsübersicht", "Produção global", "La production globale", "Genel üretim"][l];
  46. this.Data["Army overview"] = ["Truppenübersicht", "Vista Geral de Exército", "Armée aperçu", "Ordu önizlemesi"][l];
  47. this.Data["Base resources"] = ["Basis Ressourcen", "Recursos base", "ressources de base", "Üs önizlemesi"][l];
  48. this.Data["Main menu"] = ["Hauptmenü", "Menu Principal", "menu principal", "Ana menü"][l];
  49. this.Data["Repair all units"] = ["Alle Einheiten reparieren", "Reparar todas as unidades", "Réparer toutes les unités", "Tüm üniteleri onar"][l];
  50. this.Data["Repair all defense buildings"] = ["Alle Verteidigungsgebäude reparieren", "Reparar todos os edifícios de defesa", "Réparer tous les bâtiments de défense", "Tüm savunma binalarini onar"][l];
  51. this.Data["Repair all buildings"] = ["Alle Gebäurde reparieren", "Reparar todos os edifícios", "Réparer tous les bâtiments", "Tüm binalari onar"][l];
  52. this.Data["Base status overview"] = ["Basisübersicht", "Estado geral da base", "aperçu de l'état de base", "Üs durumu önizlemesi"][l];
  53. this.Data["Upgrade priority overview"] = ["Upgrade Übersicht", "Prioridade de upgrades", "aperçu des priorités de mise à niveau", "Yükseltme önceligi önizlemesi"][l];
  54. this.Data["MaelstromTools Preferences"] = ["MaelstromTools Einstellungen", "Preferências de MaelstromTools", "Préférences MaelstromTools", "MaelstromTools Ayarlari"][l];
  55. this.Data["Options"] = ["Einstellungen", "Opções", "Options", "Seçenekler"][l];
  56. this.Data["Target out of range, no resource calculation possible"] = ["Ziel nicht in Reichweite, kann die plünderbaren Ressourcen nicht berechnen", "Alvo fora do alcance, não é possivel calcular os recursos", "Cible hors de portée, pas de calcul de ressources possible",
  57. "Hedef menzil disinda, kaynak hesaplamasi olanaksiz"][l];
  58. this.Data["Lootable resources"] = ["Plünderbare Ressourcen", "Recursos roubáveis", "Ressources à piller", "Yagmalanabilir kaynaklar"][l];
  59. this.Data["per CP"] = ["pro KP", "por PC", "par PC", "KP basina"][l];
  60. this.Data["2nd run"] = ["2. Angriff", "2º ataque", "2° attaque", "2. saldiri"][l];
  61. this.Data["3rd run"] = ["3. Angriff", "3º ataque", "3° attaque", "3. saldiri"][l];
  62. this.Data["Calculating resources..."] = ["Berechne plünderbare Ressourcen...", "A calcular recursos...", "calcul de ressources ...", "Kaynaklar hesaplaniyor..."][l];
  63. this.Data["Next MCV"] = ["MBF", "MCV", "VCM"][l];
  64. this.Data["Show time to next MCV"] = ["Zeige Zeit bis zum nächsten MBF", "Mostrar tempo restante até ao próximo MCV", "Afficher l'heure pour le prochain VCM ", "Sirdaki MCV için gereken süreyi göster"][l];
  65. this.Data["Show lootable resources (restart required)"] = ["Zeige plünderbare Ressourcen (Neustart nötig)", "Mostrar recursos roubáveis (é necessário reiniciar)", "Afficher les ressources fouiller (redémarrage nécessaire)", "Yagmalanabilir kaynaklari göster (yeniden baslatma gerekli)"][l];
  66. this.Data["Use dedicated Main Menu (restart required)"] = ["Verwende extra Hauptmenü (Neustart nötig)", "Usar botão para o Menu Principal (é necessário reiniciar)", "Utiliser dédiée du menu principal (redémarrage nécessaire)", "Ana menü tusunu kullan (yeniden baslatma gerekli)"][l];
  67. this.Data["Autocollect packages"] = ["Sammle Pakete automatisch", "Auto recolher pacotes", "paquets autocollecté", "Paketleri otomatik topla"][l];
  68. this.Data["Autorepair units"] = ["Repariere Einheiten automatisch", "Auto reparar o exército", "unités autoréparé", "Üniteleri otomatik onar"][l];
  69. this.Data["Autorepair defense (higher prio than buildings)"] = ["Repariere Verteidigung automatisch (höhere Prio als Gebäude)", "Auto reparar defesa (maior prioridade do que os edifícios)", "réparation automatique la défense (priorité plus élevé que les bâtiments) ", "Savunmayi otomatik onar (binalardan daha yüksek öncelikli olarak)"][l];
  70. this.Data["Autorepair buildings"] = ["Repariere Gebäude automatisch", "Auto reparar edifícios", "bâtiments autoréparé", "Binalari otomatik onar"][l];
  71. this.Data["Automatic interval in minutes"] = ["Auto-Intervall in Minuten", "Intervalo de tempo automático (em minutos)", "intervalle automatique en quelques minutes", "Otomatik toplama araligi (dk)"][l];
  72. this.Data["Apply changes"] = ["Speichern", "Confirmar", "Appliquer changements", "Uygula"][l];
  73. this.Data["Discard changes"] = ["Abbrechen", "Cancelar", "Annuler changements", "Iptal"][l];
  74. this.Data["Reset to default"] = ["Auf Standard zurücksetzen", "Definições padrão", "Réinitialiser", "Sifirla"][l];
  75. this.Data["Continuous"] = ["Kontinuierlich", "Contínua", "continue", "Sürekli"][l];
  76. this.Data["Bonus"] = ["Pakete", "Bónus", "Bonus", "Bonus"][l];
  77. this.Data["POI"] = ["POI", "POI", "POI", "POI"][l];
  78. this.Data["Total / h"] = ["Gesamt / h", "Total / h", "Total / h", "Toplam / sa."][l];
  79. this.Data["Total / d"] = ["Gesamt / d", "Total / d", "Total / d", "Toplam / sa."][l];
  80. this.Data["Repaircharges"] = ["Reparaturzeiten", "Custo de reparação", "frais de réparation", "Onarim maliyeti"][l];
  81. this.Data["Repairtime"] = ["Max. verfügbar", "Tempo de reparação", "Temps de réparation", "Onarim süresi"][l];
  82. this.Data["Attacks"] = ["Angriffe", "Ataques", "Attaques", "Saldirilar"][l];
  83. this.Data[MaelstromTools.Statics.Infantry] = ["Infanterie", "Infantaria", "Infanterie", "Piyade"][l];
  84. this.Data[MaelstromTools.Statics.Vehicle] = ["Fahrzeuge", "Veículos", "Vehicule", "Motorlu B."][l];
  85. this.Data[MaelstromTools.Statics.Aircraft] = ["Flugzeuge", "Aeronaves", "Aviation", "Hava A."][l];
  86. this.Data[MaelstromTools.Statics.Tiberium] = ["Tiberium", "Tibério", "Tiberium", "Tiberium"][l];
  87. this.Data[MaelstromTools.Statics.Crystal] = ["Kristalle", "Cristal", "Cristal", "Kristal"][l];
  88. this.Data[MaelstromTools.Statics.Power] = ["Strom", "Potência", "Energie", "Güç"][l];
  89. this.Data[MaelstromTools.Statics.Dollar] = ["Credits", "Créditos", "Crédit", "Kredi"][l];
  90. this.Data[MaelstromTools.Statics.Research] = ["Forschung", "Investigação", "Recherche", "Arastirma"][l];
  91. this.Data["Base"] = ["Basis", "Base", "Base", "Üs"][l];
  92. this.Data["Defense"] = ["Verteidigung", "Defesa", "Défense", "Savunma"][l];
  93. this.Data["Army"] = ["Armee", "Exército", "Armée", "Ordu"][l];
  94. this.Data["Level"] = ["Stufe", "Nível", "Niveau", "Seviye"][l];
  95. this.Data["Buildings"] = ["Gebäude", "Edifícios", "Bâtiments", "Binalar"][l];
  96. this.Data["Health"] = ["Leben", "Vida", "Santé", "Saglik"][l];
  97. this.Data["Units"] = ["Einheiten", "Unidades", "Unités", "Üniteler"][l];
  98. this.Data["Hide Mission Tracker"] = ["Missionsfenster ausblenden", "Esconder janela das Missões", "Cacher la fenêtre de mission", "Görev Izleyicisini Gizle"][l];
  99. this.Data["none"] = ["keine", "nenhum", "aucun", "hiçbiri"][l];
  100. this.Data["Cooldown"] = ["Cooldown", "Relocalização", "Recharge", "Cooldown"][l];
  101. this.Data["Protection"] = ["Geschützt bis", "Protecção", "Protection", "Koruma"][l];
  102. this.Data["Available weapon"] = ["Verfügbare Artillerie", "Apoio disponível", "arme disponible", "Mevcut silah"][l];
  103. this.Data["Calibrated on"] = ["Kalibriert auf", "Calibrado em", "Calibré sur ", "Kalibreli"][l];
  104. this.Data["Total resources"] = ["Gesamt", "Total de recursos", "Ressources totales", "Toplam kaynaklar"][l];
  105. this.Data["Max. storage"] = ["Max. Kapazität", "Armazenamento Máx.", "Max. de stockage", "Maks. Depo"][l];
  106. this.Data["Storage full!"] = ["Lager voll!", "Armazenamento cheio!", "Stockage plein", "Depo dolu!"][l];
  107. this.Data["Storage"] = ["Lagerstand", "Armazenamento", "Stockage", "Depo"][l];
  108. this.Data["display only top buildings"] = ["Nur Top-Gebäude anzeigen", "Mostrar apenas melhores edifícios", "afficher uniquement les bâtiments principaux", "yalnizca en iyi binalari göster"][l];
  109. this.Data["display only affordable buildings"] = ["Nur einsetzbare Gebäude anzeigen", "Mostrar apenas edíficios acessíveis", "afficher uniquement les bâtiments abordables", "yalnizca satin alinabilir binalari göster"][l];
  110. this.Data["City"] = ["Basis", "Base", "Base", "Sehir"][l];
  111. this.Data["Type (coord)"] = ["Typ (Koord.)", "Escrever (coord)", "Type (coord)", "Tip (koord.)"][l];
  112. this.Data["to Level"] = ["Auf Stufe", "para nível", "à Niveau ", "Seviye için"][l];
  113. this.Data["Gain/h"] = ["Zuwachs/h", "Melhoria/h", "Gain / h", "Kazanç / sa."][l];
  114. this.Data["Factor"] = ["Faktor", "Factor", "Facteur", "Faktör"][l];
  115. this.Data["Tib/gain"] = ["Tib./Zuwachs", "Tib/melhoria", "Tib / gain", "Tib/Kazanç"][l];
  116. this.Data["Pow/gain"] = ["Strom/Zuwachs", "Potencia/melhoria", "Puissance / Gain", "Güç/Kazanç"][l];
  117. this.Data["ETA"] = ["Verfügbar in", "Tempo restante", "Temps restant", "Kalan Zaman"][l];
  118. this.Data["Upgrade"] = ["Aufrüsten", "Upgrade", "Upgrade", "Yükselt"][l];
  119. this.Data["Powerplant"] = ["Kratfwerk", "Central de Energia", "Centrale", "Güç Santrali"][l];
  120. this.Data["Refinery"] = ["Raffinerie", "Refinaria", "Raffinerie", "Rafineri"][l];
  121. this.Data["Harvester"] = ["Sammler", "Harvester", "Collecteur", "Biçerdöver"][l];
  122. this.Data["Silo"] = ["Silo", "Silo", "Silo", "Silo"][l];
  123. this.Data["Accumulator"] = ["Akkumulator", "Acumulador", "Accumulateur", "Akümülatör"][l];
  124. this.Data["Calibrate support"] = ["Artillerie kalibrieren", "Calibrar apoio", "Calibrer soutien", "Takviyeyi kalibre et"][l];
  125. this.Data["Access"] = ["Öffne", "Aceder", "Accès ", "Aç"][l];
  126. this.Data["Focus on"] = ["Zentriere auf", "Concentrar em", "Centré sur", "Odaklan"][l];
  127. this.Data["Possible attacks from this base (available CP)"] = ["Mögliche Angriffe (verfügbare KP)", "Possible attacks from this base (available CP)","Possible attacks from this base (available CP)", "Bu üsten yapilmasi mümkün olan saldirilar (mevcut KP)"][l];
  128. //this.Data[""] = [""][l];
  129. },
  130. get: function (ident) {
  131. return this.gt(ident);
  132. },
  133. gt: function (ident) {
  134. if (!this.Data || !this.Data[ident]) {
  135. /*if(!parseInt(ident.substr(0, 1), 10) && ident != "0") {
  136. console.log("missing language data: " + ident);
  137. }*/
  138. return ident;
  139. }
  140. return this.Data[ident];
  141. }
  142. }
  143. }),
  144.  
  145. // define Base
  146. qx.Class.define("MaelstromTools.Base", {
  147. type: "singleton",
  148. extend: qx.core.Object,
  149. members: {
  150. /* Desktop */
  151. timerInterval: 1500,
  152. mainTimerInterval: 5000,
  153. lootStatusInfoInterval: null,
  154. images: null,
  155. mWindows: null,
  156. mainMenuWindow: null,
  157.  
  158. itemsOnDesktop: null,
  159. itemsOnDesktopCount: null,
  160. itemsInMainMenu: null,
  161. itemsInMainMenuCount: null,
  162. buttonCollectAllResources: null,
  163. buttonRepairAllUnits: null,
  164. buttonRepairAllBuildings: null,
  165.  
  166. lootWidget: null,
  167.  
  168. initialize: function () {
  169. try {
  170. //console.log(qx.locale.Manager.getInstance().getLocale());
  171. Lang.loadData(ClientLib.Config.Main.GetInstance().GetConfig(ClientLib.Config.Main.CONFIG_LANGUAGE));
  172. //console.log("Client version: " + MaelstromTools.Wrapper.GetClientVersion());
  173. this.itemsOnDesktopCount = [];
  174. this.itemsOnDesktop = {};
  175. this.itemsInMainMenuCount = [];
  176. this.itemsInMainMenu = {};
  177.  
  178. var fileManager = ClientLib.File.FileManager.GetInstance();
  179. //ui/icons/icon_mainui_defense_button
  180. //ui/icons/icon_mainui_base_button
  181. //ui/icons/icon_army_points
  182. //icon_def_army_points
  183. var factionText = ClientLib.Base.Util.GetFactionGuiPatchText();
  184. this.createNewImage(MaelstromTools.Statics.Tiberium, "ui/common/icn_res_tiberium.png", fileManager);
  185. this.createNewImage(MaelstromTools.Statics.Crystal, "ui/common/icn_res_chrystal.png", fileManager);
  186. this.createNewImage(MaelstromTools.Statics.Power, "ui/common/icn_res_power.png", fileManager);
  187. this.createNewImage(MaelstromTools.Statics.Dollar, "ui/common/icn_res_dollar.png", fileManager);
  188. this.createNewImage(MaelstromTools.Statics.Research, "ui/common/icn_res_research.png", fileManager);
  189. this.createNewImage("Sum", "ui/common/icn_build_slots.png", fileManager);
  190. this.createNewImage("AccessBase", "ui/" + factionText + "/icons/icon_mainui_enterbase.png", fileManager);
  191. this.createNewImage("FocusBase", "ui/" + factionText + "/icons/icon_mainui_focusbase.png", fileManager);
  192. this.createNewImage("Packages", "ui/" + factionText + "/icons/icon_collect_packages.png", fileManager);
  193. this.createNewImage("RepairAllUnits", "ui/" + factionText + "/icons/icon_army_points.png", fileManager);
  194. this.createNewImage("RepairAllBuildings", "ui/" + factionText + "/icons/icn_build_slots.png", fileManager);
  195. this.createNewImage("ResourceOverviewMenu", "ui/common/icn_res_chrystal.png", fileManager);
  196. this.createNewImage("ProductionMenu", "ui/" + factionText + "/icons/icn_build_slots.png", fileManager);
  197. this.createNewImage("RepairTimeMenu", "ui/" + factionText + "/icons/icon_repair_all_button.png", fileManager);
  198. this.createNewImage("Crosshair", "ui/icons/icon_support_tnk_white.png", fileManager);
  199. this.createNewImage("UpgradeBuilding", "ui/" + factionText + "/icons/icon_building_detail_upgrade.png", fileManager);
  200.  
  201. this.createNewWindow("MainMenu", "R", 125, 140, 120, 100, "B");
  202. this.createNewWindow("Production", "L", 120, 60, 340, 140);
  203. this.createNewWindow("RepairTime", "L", 120, 60, 340, 140);
  204. this.createNewWindow("ResourceOverview", "L", 120, 60, 340, 140);
  205. this.createNewWindow("BaseStatusOverview", "L", 120, 60, 340, 140);
  206. this.createNewWindow("Preferences", "L", 120, 60, 440, 140);
  207. this.createNewWindow("UpgradePriority", "L", 120, 60, 1300, 400);
  208.  
  209. if (!this.mainMenuWindow) {
  210. this.mainMenuWindow = new qx.ui.popup.Popup(new qx.ui.layout.Canvas()).set({
  211. //backgroundColor: "#303030",
  212. padding: 5,
  213. paddingRight: 0
  214. });
  215. if (MT_Preferences.Settings.useDedicatedMainMenu) {
  216. this.mainMenuWindow.setPlaceMethod("mouse");
  217. this.mainMenuWindow.setPosition("top-left");
  218. } else {
  219. this.mainMenuWindow.setPlaceMethod("widget");
  220. this.mainMenuWindow.setPosition("bottom-right");
  221. this.mainMenuWindow.setAutoHide(false);
  222. this.mainMenuWindow.setBackgroundColor("transparent");
  223. //this.mainMenuWindow.setShadow(null);
  224. this.mainMenuWindow.setDecorator(new qx.ui.decoration.Decorator());
  225. }
  226. }
  227.  
  228. var desktopPositionModifier = 0;
  229.  
  230. this.buttonCollectAllResources = this.createDesktopButton(Lang.gt("Collect all packages"), "Packages", true, this.desktopPosition(desktopPositionModifier));
  231. this.buttonCollectAllResources.addListener("execute", this.collectAllPackages, this);
  232.  
  233. var openProductionWindowButton = this.createDesktopButton(Lang.gt("Overall production"), "ProductionMenu", false, this.desktopPosition(desktopPositionModifier));
  234. openProductionWindowButton.addListener("execute", function () {
  235. MaelstromTools.Production.getInstance().openWindow("Production", Lang.gt("Overall production"));
  236. }, this);
  237.  
  238. var openResourceOverviewWindowButton = this.createDesktopButton(Lang.gt("Base resources"), "ResourceOverviewMenu", false, this.desktopPosition(desktopPositionModifier));
  239. openResourceOverviewWindowButton.addListener("execute", function () {
  240. MaelstromTools.ResourceOverview.getInstance().openWindow("ResourceOverview", Lang.gt("Base resources"));
  241. }, this);
  242.  
  243. desktopPositionModifier++;
  244. var openMainMenuButton = this.createDesktopButton(Lang.gt("Main menu"), "ProductionMenu", false, this.desktopPosition(desktopPositionModifier));
  245. openMainMenuButton.addListener("click", function (e) {
  246. this.mainMenuWindow.placeToPointer(e);
  247. this.mainMenuWindow.show();
  248. }, this);
  249.  
  250. this.buttonRepairAllUnits = this.createDesktopButton(Lang.gt("Repair all units"), "RepairAllUnits", true, this.desktopPosition(desktopPositionModifier));
  251. this.buttonRepairAllUnits.addListener("execute", this.repairAllUnits, this);
  252.  
  253. this.buttonRepairAllBuildings = this.createDesktopButton(Lang.gt("Repair all buildings"), "RepairAllBuildings", true, this.desktopPosition(desktopPositionModifier));
  254. this.buttonRepairAllBuildings.addListener("execute", this.repairAllBuildings, this);
  255.  
  256. var openRepairTimeWindowButton = this.createDesktopButton(Lang.gt("Army overview"), "RepairTimeMenu", false, this.desktopPosition(desktopPositionModifier));
  257. openRepairTimeWindowButton.addListener("execute", function () {
  258. MaelstromTools.RepairTime.getInstance().openWindow("RepairTime", Lang.gt("Army overview"));
  259. }, this);
  260.  
  261. var openBaseStatusOverview = this.createDesktopButton(Lang.gt("Base status overview"), "Crosshair", false, this.desktopPosition(desktopPositionModifier));
  262. openBaseStatusOverview.addListener("execute", function () {
  263. MaelstromTools.BaseStatus.getInstance().openWindow("BaseStatusOverview", Lang.gt("Base status overview"));
  264. }, this);
  265.  
  266. desktopPositionModifier++;
  267. var openHuffyUpgradeOverview = this.createDesktopButton(Lang.gt("Upgrade priority overview"), "UpgradeBuilding", false, this.desktopPosition(desktopPositionModifier));
  268. openHuffyUpgradeOverview.addListener("execute", function () {
  269. HuffyTools.UpgradePriorityGUI.getInstance().openWindow("UpgradePriority", Lang.gt("Upgrade priority overview"));
  270. }, this);
  271.  
  272. desktopPositionModifier++;
  273. var preferencesButton = new qx.ui.form.Button(Lang.gt("Options")).set({
  274. appearance: "button-text-small",
  275. width: 100,
  276. minWidth: 100,
  277. maxWidth: 100
  278. });
  279. preferencesButton.setUserData("desktopPosition", this.desktopPosition(desktopPositionModifier));
  280. preferencesButton.addListener("execute", function () {
  281. MaelstromTools.Preferences.getInstance().openWindow("Preferences", Lang.gt("MaelstromTools version 0.1.4.48 Preferences"), true);
  282. }, this);
  283.  
  284. if (MT_Preferences.Settings.useDedicatedMainMenu) {
  285. this.addToDesktop("MainMenu", openMainMenuButton);
  286. }
  287. this.addToMainMenu("ResourceOverviewMenu", openResourceOverviewWindowButton);
  288. this.addToMainMenu("ProductionMenu", openProductionWindowButton);
  289. this.addToMainMenu("BaseStatusMenu", openBaseStatusOverview);
  290. this.addToMainMenu("RepairTimeMenu", openRepairTimeWindowButton);
  291. this.addToMainMenu("UpgradeBuilding", openHuffyUpgradeOverview);
  292.  
  293. this.addToMainMenu("PreferencesMenu", preferencesButton);
  294.  
  295. if (!MT_Preferences.Settings.useDedicatedMainMenu) {
  296. this.mainMenuWindow.show();
  297. var target = qx.core.Init.getApplication().getOptionsBar(); //getServerBar(); //qx.core.Init.getApplication().getUIItem(ClientLib.Data.Missions.PATH.BAR_APPOINTMENTS);
  298. this.mainMenuWindow.placeToWidget(target, true);
  299. }
  300.  
  301. phe.cnc.Util.attachNetEvent(ClientLib.Data.MainData.GetInstance().get_Cities(), "CurrentOwnChange", ClientLib.Data.CurrentOwnCityChange, this, function () {
  302. MaelstromTools.Cache.getInstance().SelectedBaseForLoot=null;
  303. });
  304.  
  305. webfrontend.gui.chat.ChatWidget.recvbufsize = MaelstromTools.LocalStorage.get(MaelstromTools.Preferences.CHATHISTORYLENGTH, 64);
  306. this.runSecondlyTimer();
  307. this.runMainTimer();
  308. this.runAutoCollectTimer();
  309. } catch (e) {
  310. console.log("MaelstromTools.initialize: ", e);
  311. }
  312. },
  313.  
  314. desktopPosition: function (modifier) {
  315. if (!modifier) modifier = 0;
  316. return modifier;
  317. },
  318.  
  319. createDesktopButton: function (title, imageName, isNotification, desktopPosition) {
  320. try {
  321. if (!isNotification) {
  322. isNotification = false;
  323. }
  324. if (!desktopPosition) {
  325. desktopPosition = this.desktopPosition();
  326. }
  327. var desktopButton = new qx.ui.form.Button(null, this.images[imageName]).set({
  328. toolTipText: title,
  329. width: 50,
  330. height: 40,
  331. maxWidth: 50,
  332. maxHeight: 40,
  333. appearance: (isNotification ? "button-standard-nod" : "button-playarea-mode-frame"), //"button-standard-"+factionText), button-playarea-mode-red-frame
  334. center: true
  335. });
  336.  
  337. desktopButton.setUserData("isNotification", isNotification);
  338. desktopButton.setUserData("desktopPosition", desktopPosition);
  339. return desktopButton;
  340. } catch (e) {
  341. console.log("MaelstromTools.createDesktopButton: ", e);
  342. }
  343. },
  344.  
  345. createNewImage: function (name, path, fileManager) {
  346. try {
  347. if (!this.images) {
  348. this.images = {};
  349. }
  350. if (!fileManager) {
  351. return;
  352. }
  353.  
  354. this.images[name] = fileManager.GetPhysicalPath(path);
  355. } catch (e) {
  356. console.log("MaelstromTools.createNewImage: ", e);
  357. }
  358. },
  359.  
  360. createNewWindow: function (name, align, x, y, w, h, alignV) {
  361. try {
  362. if (!this.mWindows) {
  363. this.mWindows = {};
  364. }
  365. this.mWindows[name] = {};
  366. this.mWindows[name]["Align"] = align;
  367. this.mWindows[name]["AlignV"] = alignV;
  368. this.mWindows[name]["x"] = x;
  369. this.mWindows[name]["y"] = y;
  370. this.mWindows[name]["w"] = w;
  371. this.mWindows[name]["h"] = h;
  372. } catch (e) {
  373. console.log("MaelstromTools.createNewWindow: ", e);
  374. }
  375. },
  376.  
  377. addToMainMenu: function (name, button) {
  378. try {
  379. /*if(!this.useDedicatedMainMenu) {
  380. return;
  381. }*/
  382. if (this.itemsInMainMenu[name] != null) {
  383. return;
  384. }
  385. var desktopPosition = button.getUserData("desktopPosition");
  386. var isNotification = button.getUserData("isNotification");
  387. if (!desktopPosition) {
  388. desktopPosition = this.desktopPosition();
  389. }
  390. if (!isNotification) {
  391. isNotification = false;
  392. }
  393.  
  394. if (isNotification && MT_Preferences.Settings.useDedicatedMainMenu) {
  395. this.addToDesktop(name, button);
  396. } else {
  397. if (!this.itemsInMainMenuCount[desktopPosition]) {
  398. this.itemsInMainMenuCount[desktopPosition] = 0;
  399. }
  400. this.mainMenuWindow.add(button, {
  401. right: 5 + (52 * this.itemsInMainMenuCount[desktopPosition]),
  402. top: 0 + (42 * (desktopPosition)) //bottom: 0 - (42 * (desktopPosition - 1))
  403. });
  404.  
  405. this.itemsInMainMenu[name] = button;
  406. this.itemsInMainMenuCount[desktopPosition]++;
  407. }
  408. } catch (e) {
  409. console.log("MaelstromTools.addToMainMenu: ", e);
  410. }
  411. },
  412.  
  413. removeFromMainMenu: function (name, rearrange) {
  414. try {
  415. if (rearrange == null) {
  416. rearrange = true;
  417. }
  418. if (this.itemsOnDesktop[name] != null) {
  419. var isNotification = this.itemsOnDesktop[name].getUserData("isNotification");
  420. if (!isNotification) {
  421. isNotification = false;
  422. }
  423. if (isNotification && MT_Preferences.Settings.useDedicatedMainMenu) {
  424. this.removeFromDesktop(name, rearrange);
  425. }
  426. } else if (this.itemsInMainMenu[name] != null) {
  427. var desktopPosition = this.itemsInMainMenu[name].getUserData("desktopPosition");
  428. var isNotification = this.itemsInMainMenu[name].getUserData("isNotification");
  429. if (!desktopPosition) {
  430. desktopPosition = this.desktopPosition();
  431. }
  432. if (!isNotification) {
  433. isNotification = false;
  434. }
  435.  
  436. this.mainMenuWindow.remove(this.itemsInMainMenu[name]);
  437. this.itemsInMainMenu[name] = null;
  438. this.itemsInMainMenuCount[desktopPosition]--;
  439.  
  440. if (rearrange && this.itemsInMainMenu[desktopPosition] > 1) {
  441. var tmpItems = {};
  442. // remove notifications
  443. for (var itemName in this.itemsOnDesktop) {
  444. if (this.itemsInMainMenu[itemName] == null) {
  445. continue;
  446. }
  447. if (!isNotification) {
  448. continue;
  449. }
  450. tmpItems[itemName] = this.itemsInMainMenu[itemName];
  451. this.removeFromMainMenu(itemName, false);
  452. }
  453. // rearrange notifications
  454. for (var itemName2 in tmpItems) {
  455. var tmp = tmpItems[itemName2];
  456. if (tmp == null) {
  457. continue;
  458. }
  459. this.addToMainMenu(itemName2, tmp);
  460. }
  461. }
  462. }
  463. } catch (e) {
  464. console.log("MaelstromTools.removeFromDesktop: ", e);
  465. }
  466. },
  467.  
  468. addToDesktop: function (name, button) {
  469. try {
  470. if (this.itemsOnDesktop[name] != null) {
  471. return;
  472. }
  473. var desktopPosition = button.getUserData("desktopPosition");
  474. if (!desktopPosition) {
  475. desktopPosition = this.desktopPosition();
  476. }
  477.  
  478. if (!this.itemsOnDesktopCount[desktopPosition]) {
  479. this.itemsOnDesktopCount[desktopPosition] = 0;
  480. }
  481.  
  482. var app = qx.core.Init.getApplication();
  483. //var navBar = app.getNavigationBar();
  484.  
  485. // console.log("add to Desktop at pos: " + this.itemsOnDesktopCount);
  486. app.getDesktop().add(button, {
  487. //right: navBar.getBounds().width + (52 * this.itemsOnDesktopCount[desktopPosition]),
  488. //top: 42 * (desktopPosition - 1)
  489. right: 5 + (52 * this.itemsOnDesktopCount[desktopPosition]),
  490. //top: this.initialAppointmentBarHeight + 125 + (42 * (desktopPosition - 1))
  491. bottom: 104 - (42 * (desktopPosition - 1)) //bottom: 140 - (42 * (desktopPosition - 1))
  492. });
  493.  
  494. this.itemsOnDesktop[name] = button;
  495. this.itemsOnDesktopCount[desktopPosition]++;
  496. } catch (e) {
  497. console.log("MaelstromTools.addToDesktop: ", e);
  498. }
  499. },
  500.  
  501. removeFromDesktop: function (name, rearrange) {
  502. try {
  503. if (rearrange == null) {
  504. rearrange = true;
  505. }
  506. var app = qx.core.Init.getApplication();
  507.  
  508. if (this.itemsOnDesktop[name] != null) {
  509. var desktopPosition = this.itemsOnDesktop[name].getUserData("desktopPosition");
  510. var isNotification = this.itemsOnDesktop[name].getUserData("isNotification");
  511. if (!desktopPosition) {
  512. desktopPosition = this.desktopPosition();
  513. }
  514. if (!isNotification) {
  515. isNotification = false;
  516. }
  517.  
  518. app.getDesktop().remove(this.itemsOnDesktop[name]);
  519. this.itemsOnDesktop[name] = null;
  520. this.itemsOnDesktopCount[desktopPosition]--;
  521.  
  522. if (rearrange && this.itemsOnDesktopCount[desktopPosition] > 1) {
  523. var tmpItems = {};
  524. // remove notifications
  525. for (var itemName in this.itemsOnDesktop) {
  526. if (this.itemsOnDesktop[itemName] == null) {
  527. continue;
  528. }
  529. if (!this.itemsOnDesktop[itemName].getUserData("isNotification")) {
  530. continue;
  531. }
  532. tmpItems[itemName] = this.itemsOnDesktop[itemName];
  533. this.removeFromDesktop(itemName, false);
  534. }
  535. // rearrange notifications
  536. for (var itemName2 in tmpItems) {
  537. var tmp = tmpItems[itemName2];
  538. if (tmp == null) {
  539. continue;
  540. }
  541. this.addToMainMenu(itemName2, tmp);
  542. }
  543. }
  544. }
  545. } catch (e) {
  546. console.log("MaelstromTools.removeFromDesktop: ", e);
  547. }
  548. },
  549.  
  550. runSecondlyTimer: function () {
  551. try {
  552. this.calculateCostsForNextMCV();
  553.  
  554. var self = this;
  555. setTimeout(function () {
  556. self.runSecondlyTimer();
  557. }, 1000);
  558. } catch (e) {
  559. console.log("MaelstromTools.runSecondlyTimer: ", e);
  560. }
  561. },
  562.  
  563. runMainTimer: function () {
  564. try {
  565. this.checkForPackages();
  566. this.checkRepairAllUnits();
  567. this.checkRepairAllBuildings();
  568.  
  569. var missionTracker = typeof (qx.core.Init.getApplication().getMissionsBar) === 'function' ? qx.core.Init.getApplication().getMissionsBar() : qx.core.Init.getApplication().getMissionTracker(); //fix for PerforceChangelist>=376877
  570. if (MT_Preferences.Settings.autoHideMissionTracker) {
  571. if (missionTracker.isVisible()) {
  572. missionTracker.hide();
  573. }
  574. if (typeof (qx.core.Init.getApplication().getMissionsBar) === 'function') {
  575. if (qx.core.Init.getApplication().getMissionsBar().getSizeHint().height != 0) {
  576. qx.core.Init.getApplication().getMissionsBar().getSizeHint().height = 0;
  577. qx.core.Init.getApplication().triggerDesktopResize();
  578. }
  579. }
  580. } else {
  581. if (!missionTracker.isVisible()) {
  582. missionTracker.show();
  583. if (typeof (qx.core.Init.getApplication().getMissionsBar) === 'function') {
  584. qx.core.Init.getApplication().getMissionsBar().initHeight();
  585. qx.core.Init.getApplication().triggerDesktopResize();
  586. }
  587. }
  588. }
  589. var self = this;
  590. setTimeout(function () {
  591. self.runMainTimer();
  592. }, this.mainTimerInterval);
  593. } catch (e) {
  594. console.log("MaelstromTools.runMainTimer: ", e);
  595. }
  596. },
  597.  
  598. runAutoCollectTimer: function () {
  599. try {
  600. //console.log("runAutoCollectTimer ", MT_Preferences.Settings.AutoCollectTimer);
  601. if (!CCTAWrapperIsInstalled()) return; // run timer only then wrapper is running
  602. if (this.checkForPackages() && MT_Preferences.Settings.autoCollectPackages) {
  603. this.collectAllPackages();
  604. }
  605. if (this.checkRepairAllUnits() && MT_Preferences.Settings.autoRepairUnits) {
  606. this.repairAllUnits();
  607. }
  608. if (this.checkRepairAllBuildings() && MT_Preferences.Settings.autoRepairBuildings) {
  609. this.repairAllBuildings();
  610. }
  611.  
  612. var self = this;
  613. setTimeout(function () {
  614. self.runAutoCollectTimer();
  615. }, MT_Preferences.Settings.AutoCollectTimer * 60000);
  616. } catch (e) {
  617. console.log("MaelstromTools.runMainTimer: ", e);
  618. }
  619. },
  620.  
  621. openWindow: function (windowObj, windowName, skipMoveWindow) {
  622. try {
  623. if (!windowObj.isVisible()) {
  624. if (windowName == "MainMenu") {
  625. windowObj.show();
  626. } else {
  627. if (!skipMoveWindow) {
  628. this.moveWindow(windowObj, windowName);
  629. }
  630. windowObj.open();
  631. }
  632. }
  633. } catch (e) {
  634. console.log("MaelstromTools.openWindow: ", e);
  635. }
  636. },
  637.  
  638. moveWindow: function (windowObj, windowName) {
  639. try {
  640. var x = this.mWindows[windowName]["x"];
  641. var y = this.mWindows[windowName]["y"];
  642. if (this.mWindows[windowName]["Align"] == "R") {
  643. x = qx.bom.Viewport.getWidth(window) - this.mWindows[windowName]["x"];
  644. }
  645. if (this.mWindows[windowName]["AlignV"] == "B") {
  646. y = qx.bom.Viewport.getHeight(window) - this.mWindows[windowName]["y"] - windowObj.height;
  647. }
  648. windowObj.moveTo(x, y);
  649. if (windowName != "MainMenu") {
  650. windowObj.setHeight(this.mWindows[windowName]["h"]);
  651. windowObj.setWidth(this.mWindows[windowName]["w"]);
  652. }
  653. } catch (e) {
  654. console.log("MaelstromTools.moveWindow: ", e);
  655. }
  656. },
  657.  
  658. checkForPackages: function () {
  659. try {
  660. MT_Cache.updateCityCache();
  661.  
  662. for (var cname in MT_Cache.Cities) {
  663. var ncity = MT_Cache.Cities[cname].Object;
  664. if (ncity.get_CityBuildingsData().get_HasCollectableBuildings() && !ncity.get_IsGhostMode()) {
  665. this.addToMainMenu("CollectAllResources", this.buttonCollectAllResources);
  666. return true;
  667. }
  668. }
  669. this.removeFromMainMenu("CollectAllResources");
  670. return false;
  671. } catch (e) {
  672. console.log("MaelstromTools.checkForPackages: ", e);
  673. return false;
  674. }
  675. },
  676.  
  677. collectAllPackages: function () {
  678. try {
  679. MT_Cache.updateCityCache();
  680. for (var cname in MT_Cache.Cities) {
  681. var ncity = MT_Cache.Cities[cname].Object;
  682. if (ncity.get_CityBuildingsData().get_HasCollectableBuildings()) {
  683. ncity.CollectAllResources();
  684. }
  685. }
  686. this.removeFromMainMenu("CollectAllResources");
  687. } catch (e) {
  688. console.log("MaelstromTools.collectAllPackages: ", e);
  689. }
  690. },
  691.  
  692. checkRepairAll: function (visMode, buttonName, button) {
  693. try {
  694. MT_Cache.updateCityCache();
  695.  
  696. for (var cname in MT_Cache.Cities) {
  697. var ncity = MT_Cache.Cities[cname].Object;
  698. if (!ncity.get_IsGhostMode() && ncity.get_CityRepairData().CanRepairAll(visMode)) {
  699. this.addToMainMenu(buttonName, button);
  700. return true;
  701. }
  702. }
  703.  
  704. this.removeFromMainMenu(buttonName);
  705. return false;
  706. } catch (e) {
  707. console.log("MaelstromTools.checkRepairAll: ", e);
  708. return false;
  709. }
  710. },
  711.  
  712. checkRepairAllUnits: function () {
  713. return this.checkRepairAll(ClientLib.Vis.Mode.ArmySetup, "RepairAllUnits", this.buttonRepairAllUnits);
  714. },
  715.  
  716. checkRepairAllBuildings: function () {
  717. return this.checkRepairAll(ClientLib.Vis.Mode.City, "RepairAllBuildings", this.buttonRepairAllBuildings);
  718. },
  719.  
  720. repairAll: function (visMode, buttonName) {
  721. try {
  722. MT_Cache.updateCityCache();
  723.  
  724. for (var cname in MT_Cache.Cities) {
  725. var ncity = MT_Cache.Cities[cname].Object;
  726. if (!ncity.get_IsGhostMode() && ncity.get_CityRepairData().CanRepairAll(visMode)) {
  727. ncity.get_CityRepairData().RepairAll(visMode);
  728. }
  729.  
  730. }
  731. this.removeFromMainMenu(buttonName);
  732. } catch (e) {
  733. console.log("MaelstromTools.repairAll: ", e);
  734. }
  735. },
  736.  
  737. //ClientLib.Data.City.prototype.get_CityRepairData
  738. //ClientLib.Data.CityRepair.prototype.CanRepairAll
  739. //ClientLib.Data.CityRepair.prototype.RepairAll
  740. repairAllUnits: function () {
  741. try {
  742. this.repairAll(ClientLib.Vis.Mode.ArmySetup, "RepairAllUnits");
  743. } catch (e) {
  744. console.log("MaelstromTools.repairAllUnits: ", e);
  745. }
  746. },
  747.  
  748. repairAllBuildings: function () {
  749. try {
  750. this.repairAll(ClientLib.Vis.Mode.City, "RepairAllBuildings");
  751. } catch (e) {
  752. console.log("MaelstromTools.repairAllBuildings: ", e);
  753. }
  754. },
  755.  
  756. updateLoot: function (ident, visCity, widget) {
  757. try {
  758. clearInterval(this.lootStatusInfoInterval);
  759. if (!MT_Preferences.Settings.showLoot) {
  760. if (this.lootWidget[ident]) {
  761. this.lootWidget[ident].removeAll();
  762. }
  763. return;
  764. }
  765.  
  766. var baseLoadState = MT_Cache.updateLoot(visCity);
  767. if (baseLoadState == -2) { // base already cached and base not changed
  768. return;
  769. }
  770.  
  771. if (!this.lootWidget) {
  772. this.lootWidget = {};
  773. }
  774. if (!this.lootWidget[ident]) {
  775. this.lootWidget[ident] = new qx.ui.container.Composite(new qx.ui.layout.Grid(5, 5));
  776. this.lootWidget[ident].setTextColor("white");
  777. widget.add(this.lootWidget[ident]);
  778. }
  779. var lootWidget = this.lootWidget[ident];
  780.  
  781. var rowIdx = 1;
  782. var colIdx = 1;
  783. lootWidget.removeAll();
  784. switch (baseLoadState) {
  785. case -1:
  786. {
  787. MaelstromTools.Util.addLabel(lootWidget, rowIdx, colIdx++, "Target out of range, no resource calculation possible", null, null, 'bold', null);
  788. break;
  789. }
  790. case 1:
  791. {
  792. var Resources = MT_Cache.SelectedBaseResources;
  793. this.createResourceLabels(lootWidget, ++rowIdx, "Possible attacks from this base (available CP)", Resources, - 1);
  794. this.createResourceLabels(lootWidget, ++rowIdx, "Lootable resources", Resources, 1);
  795. this.createResourceLabels(lootWidget, ++rowIdx, "per CP", Resources, 1 * Resources.CPNeeded);
  796. this.createResourceLabels(lootWidget, ++rowIdx, "2nd run", Resources, 2 * Resources.CPNeeded);
  797. this.createResourceLabels(lootWidget, ++rowIdx, "3rd run", Resources, 3 * Resources.CPNeeded);
  798. break;
  799. }
  800. default:
  801. {
  802. MaelstromTools.Util.addLabel(lootWidget, rowIdx, colIdx++, "Calculating resources...", null, null, 'bold', null);
  803. this.lootStatusInfoInterval = setInterval(function () {
  804. MaelstromTools.Base.getInstance().updateLoot(ident, visCity, widget);
  805. }, 100);
  806. break;
  807. }
  808. }
  809. } catch (e) {
  810. console.log("MaelstromTools.updateLoot: ", e);
  811. }
  812. },
  813.  
  814. createResourceLabels: function (lootWidget, rowIdx, Label, Resources, Modifier) {
  815. var colIdx = 1;
  816. var font = (Modifier > 1 ? null : 'bold');
  817.  
  818. if (Modifier == -1 && Resources.CPNeeded > 0) {
  819. Label = Lang.gt(Label) + ": " + Math.floor(ClientLib.Data.MainData.GetInstance().get_Player().GetCommandPointCount() / Resources.CPNeeded);
  820. MaelstromTools.Util.addLabel(lootWidget, rowIdx, colIdx++, Label, null, 'left', font, null, 9);
  821. return;
  822. }
  823. colIdx = 1;
  824. if (Modifier > 0) {
  825. MaelstromTools.Util.addLabel(lootWidget, rowIdx, colIdx++, Lang.gt(Label) + ":", null, null, font);
  826. MaelstromTools.Util.addImage(lootWidget, rowIdx, colIdx++, MaelstromTools.Util.getImage(MaelstromTools.Statics.Research));
  827. MaelstromTools.Util.addLabel(lootWidget, rowIdx, colIdx++, MaelstromTools.Wrapper.FormatNumbersCompact(Resources[MaelstromTools.Statics.Research] / Modifier), 50, 'right', font);
  828. MaelstromTools.Util.addImage(lootWidget, rowIdx, colIdx++, MaelstromTools.Util.getImage(MaelstromTools.Statics.Tiberium));
  829. MaelstromTools.Util.addLabel(lootWidget, rowIdx, colIdx++, MaelstromTools.Wrapper.FormatNumbersCompact(Resources[MaelstromTools.Statics.Tiberium] / Modifier), 50, 'right', font);
  830. MaelstromTools.Util.addImage(lootWidget, rowIdx, colIdx++, MaelstromTools.Util.getImage(MaelstromTools.Statics.Crystal));
  831. MaelstromTools.Util.addLabel(lootWidget, rowIdx, colIdx++, MaelstromTools.Wrapper.FormatNumbersCompact(Resources[MaelstromTools.Statics.Crystal] / Modifier), 50, 'right', font);
  832. MaelstromTools.Util.addImage(lootWidget, rowIdx, colIdx++, MaelstromTools.Util.getImage(MaelstromTools.Statics.Dollar));
  833. MaelstromTools.Util.addLabel(lootWidget, rowIdx, colIdx++, MaelstromTools.Wrapper.FormatNumbersCompact(Resources[MaelstromTools.Statics.Dollar] / Modifier), 50, 'right', font);
  834. MaelstromTools.Util.addImage(lootWidget, rowIdx, colIdx++, MaelstromTools.Util.getImage("Sum"));
  835. MaelstromTools.Util.addLabel(lootWidget, rowIdx, colIdx++, MaelstromTools.Wrapper.FormatNumbersCompact(Resources["Total"] / Modifier), 50, 'right', font);
  836. }
  837. },
  838.  
  839. mcvPopup: null,
  840. mcvPopupX : 0,
  841. mcvPopupY : 0,
  842. mcvTimerLabel: null,
  843. mcvCreditProcentageLabel: null,
  844. mcvResearchTimerLabel: null,
  845. calculateCostsForNextMCV: function () {
  846. try {
  847. if (!MT_Preferences.Settings.showCostsForNextMCV) {
  848. if (this.mcvPopup) {
  849. this.mcvPopup.close();
  850. }
  851. return;
  852. }
  853. var player = ClientLib.Data.MainData.GetInstance().get_Player();
  854. var cw = player.get_Faction();
  855. var cj = ClientLib.Base.Tech.GetTechIdFromTechNameAndFaction(ClientLib.Base.ETechName.Research_BaseFound, cw);
  856. var cr = player.get_PlayerResearch();
  857. var cd = cr.GetResearchItemFomMdbId(cj);
  858. if (cd == null) {
  859. if (this.mcvPopup) {
  860. this.mcvPopup.close();
  861. }
  862. return;
  863. }
  864.  
  865. if (!this.mcvPopup) {
  866. this.mcvPopup = new qx.ui.window.Window("").set({
  867. contentPadding : 0,
  868. showMinimize : false,
  869. showMaximize : false,
  870. showClose : false,
  871. resizable : false
  872. });
  873. this.mcvPopup.setLayout(new qx.ui.layout.VBox());
  874. this.mcvPopup.addListener("move", function (e) {
  875. var base = MaelstromTools.Base.getInstance();
  876. var size = qx.core.Init.getApplication().getRoot().getBounds();
  877. var value = size.width - e.getData().left;
  878. base.mcvPopupX = value < 0 ? 150 : value;
  879. value = size.height - e.getData().top;
  880. base.mcvPopupY = value < 0 ? 70 : value;
  881. MaelstromTools.LocalStorage.set("mcvPopup", {
  882. x : base.mcvPopupX,
  883. y : base.mcvPopupY
  884. });
  885. });
  886. var font1 = qx.bom.Font.fromString('bold').set({
  887. size: 15
  888. });
  889. var font2 = qx.bom.Font.fromString('bold').set({
  890. size: 14
  891. });
  892. var font3 = qx.bom.Font.fromString('bold').set({
  893. size: 14
  894. });
  895. this.mcvTimerLabel = new qx.ui.basic.Label().set({
  896. font: font1,
  897. textColor: 'cyan',
  898. width: 155,
  899. textAlign: 'center',
  900. marginBottom : 5
  901. });
  902. this.mcvCreditProcentageLabel = new qx.ui.basic.Label().set({
  903. font: font2,
  904. textColor: 'yellow',
  905. width: 155,
  906. textAlign: 'center',
  907. marginBottom : 5
  908. });
  909. this.mcvResearchTimerLabel = new qx.ui.basic.Label().set({
  910. font: font3,
  911. textColor: 'yellow',
  912. width: 155,
  913. textAlign: 'center',
  914. marginBottom : 5
  915. });
  916. this.mcvPopup.add(this.mcvTimerLabel);
  917. this.mcvPopup.add(this.mcvCreditProcentageLabel);
  918. this.mcvPopup.add(this.mcvResearchTimerLabel);
  919. var serverBar = qx.core.Init.getApplication().getServerBar().getBounds();
  920. var pos = MaelstromTools.LocalStorage.get("mcvPopup", {
  921. x : serverBar.width + 30,
  922. y : 120
  923. });
  924. this.mcvPopupX = pos.x;
  925. this.mcvPopupY = pos.y;
  926. this.mcvPopup.open();
  927. }
  928. var size = qx.core.Init.getApplication().getRoot().getBounds();
  929. this.mcvPopup.moveTo(size.width - this.mcvPopupX, size.height - this.mcvPopupY);
  930.  
  931. var nextLevelInfo = cd.get_NextLevelInfo_Obj();
  932. var resourcesNeeded = [];
  933. for (var i in nextLevelInfo.rr) {
  934. if (nextLevelInfo.rr[i].t > 0) {
  935. resourcesNeeded[nextLevelInfo.rr[i].t] = nextLevelInfo.rr[i].c;
  936. }
  937. }
  938. var researchNeeded = resourcesNeeded[ClientLib.Base.EResourceType.ResearchPoints];
  939. var currentResearchPoints = player.get_ResearchPoints();
  940. XY = 100 / researchNeeded
  941. XYX = currentResearchPoints
  942. PercentageOfResearchPoints = XYX * XY
  943. //PercentageOfResearchPoints = 150.23
  944. var creditsNeeded = resourcesNeeded[ClientLib.Base.EResourceType.Gold];
  945. var creditsResourceData = player.get_Credits();
  946. var creditGrowthPerHour = (creditsResourceData.Delta + creditsResourceData.ExtraBonusDelta) * ClientLib.Data.MainData.GetInstance().get_Time().get_StepsPerHour();
  947. var creditTimeLeftInHours = (creditsNeeded - player.GetCreditsCount()) / creditGrowthPerHour;
  948. var ZX = 100 / creditsNeeded;
  949. var ZXZ = player.GetCreditsCount();
  950. var PercentageOfCredits = ZXZ * ZX
  951. //PercentageOfCredits = ZXZ * 1% of ZX
  952.  
  953. //if (creditGrowthPerHour == 0 || creditTimeLeftInHours <= 0) {
  954. // if (this.mcvPopup) {
  955. // this.mcvPopup.close();
  956. // }
  957. // return;
  958. //}
  959. this.mcvPopup.setCaption(Lang.gt("Next MCV") + " ($ " + MaelstromTools.Wrapper.FormatNumbersCompact(creditsNeeded) + ")");
  960. if (creditTimeLeftInHours > 0) {
  961. this.mcvTimerLabel.setValue("$-timer : " + MaelstromTools.Wrapper.FormatTimespan(creditTimeLeftInHours * 60 * 60));
  962. } else {
  963. this.mcvTimerLabel.setValue("");
  964. }
  965. if (PercentageOfCredits >= 100) {
  966. this.mcvCreditProcentageLabel.setValue("Credits READY");
  967. }
  968. if (PercentageOfCredits < 100) {
  969. this.mcvCreditProcentageLabel.setValue("Credits @ " + (PercentageOfCredits).toFixed(2) + "%");
  970. }
  971. if (PercentageOfResearchPoints >= 100) {
  972. this.mcvResearchTimerLabel.setValue("Res.Points READY");
  973. }
  974. if (PercentageOfResearchPoints < 100) {
  975. this.mcvResearchTimerLabel.setValue("Res.Points @ " + (PercentageOfResearchPoints).toFixed(2) + "%");
  976. }
  977. if (!this.mcvPopup.isVisible()) {
  978. this.mcvPopup.open();
  979. }
  980. } catch (e) {
  981. console.log("calculateCostsForNextMCV", e);
  982. }
  983. }
  984. }
  985. });
  986.  
  987. // define Preferences
  988. qx.Class.define("MaelstromTools.Preferences", {
  989. type: "singleton",
  990. extend: qx.core.Object,
  991.  
  992. statics: {
  993. USEDEDICATEDMAINMENU: "useDedicatedMainMenu",
  994. AUTOCOLLECTPACKAGES: "autoCollectPackages",
  995. AUTOREPAIRUNITS: "autoRepairUnits",
  996. AUTOREPAIRBUILDINGS: "autoRepairBuildings",
  997. AUTOHIDEMISSIONTRACKER: "autoHideMissionTracker",
  998. AUTOCOLLECTTIMER: "AutoCollectTimer",
  999. SHOWLOOT: "showLoot",
  1000. SHOWCOSTSFORNEXTMCV: "showCostsForNextMCV",
  1001. CHATHISTORYLENGTH: "ChatHistoryLength"
  1002. },
  1003.  
  1004. members: {
  1005. Window: null,
  1006. Widget: null,
  1007. Settings: null,
  1008. FormElements: null,
  1009.  
  1010. readOptions: function () {
  1011. try {
  1012. if (!this.Settings) {
  1013. this.Settings = {};
  1014. }
  1015.  
  1016. /*
  1017. if(MaelstromTools.LocalStorage.get("useDedicatedMainMenu") == null) {
  1018. if(qx.bom.Viewport.getWidth(window) > 1800) {
  1019. this.Settings["useDedicatedMainMenu"] = false;
  1020. }
  1021. } else {
  1022. this.Settings["useDedicatedMainMenu"] = (MaelstromTools.LocalStorage.get("useDedicatedMainMenu", 1) == 1);
  1023. }*/
  1024. this.Settings[MaelstromTools.Preferences.USEDEDICATEDMAINMENU] = (MaelstromTools.LocalStorage.get(MaelstromTools.Preferences.USEDEDICATEDMAINMENU, 1) == 1);
  1025. this.Settings[MaelstromTools.Preferences.AUTOCOLLECTPACKAGES] = (MaelstromTools.LocalStorage.get(MaelstromTools.Preferences.AUTOCOLLECTPACKAGES, 1) == 1);
  1026. this.Settings[MaelstromTools.Preferences.AUTOREPAIRUNITS] = (MaelstromTools.LocalStorage.get(MaelstromTools.Preferences.AUTOREPAIRUNITS, 0) == 1);
  1027. this.Settings[MaelstromTools.Preferences.AUTOREPAIRBUILDINGS] = (MaelstromTools.LocalStorage.get(MaelstromTools.Preferences.AUTOREPAIRBUILDINGS, 1) == 1);
  1028. this.Settings[MaelstromTools.Preferences.AUTOHIDEMISSIONTRACKER] = (MaelstromTools.LocalStorage.get(MaelstromTools.Preferences.AUTOHIDEMISSIONTRACKER, 0) == 1);
  1029. this.Settings[MaelstromTools.Preferences.AUTOCOLLECTTIMER] = MaelstromTools.LocalStorage.get(MaelstromTools.Preferences.AUTOCOLLECTTIMER, 5);
  1030. this.Settings[MaelstromTools.Preferences.SHOWLOOT] = (MaelstromTools.LocalStorage.get(MaelstromTools.Preferences.SHOWLOOT, 1) == 1);
  1031. this.Settings[MaelstromTools.Preferences.SHOWCOSTSFORNEXTMCV] = (MaelstromTools.LocalStorage.get(MaelstromTools.Preferences.SHOWCOSTSFORNEXTMCV, 0) == 1);
  1032. this.Settings[MaelstromTools.Preferences.CHATHISTORYLENGTH] = MaelstromTools.LocalStorage.get(MaelstromTools.Preferences.CHATHISTORYLENGTH, 512);
  1033.  
  1034. if (!CCTAWrapperIsInstalled()) {
  1035. this.Settings[MaelstromTools.Preferences.AUTOREPAIRUNITS] = false;
  1036. this.Settings[MaelstromTools.Preferences.AUTOREPAIRBUILDINGS] = false;
  1037. //this.Settings[MaelstromTools.Preferences.SHOWLOOT] = false;
  1038. }
  1039. //console.log(this.Settings);
  1040.  
  1041. } catch (e) {
  1042. console.log("MaelstromTools.Preferences.readOptions: ", e);
  1043. }
  1044. },
  1045.  
  1046. openWindow: function (WindowName, WindowTitle) {
  1047. try {
  1048. if (!this.Window) {
  1049. //this.Window = new qx.ui.window.Window(WindowTitle).set({
  1050. this.Window = new webfrontend.gui.OverlayWindow().set({
  1051. autoHide: false,
  1052. title: WindowTitle,
  1053. minHeight: 350
  1054.  
  1055. //resizable: false,
  1056. //showMaximize:false,
  1057. //showMinimize:false,
  1058. //allowMaximize:false,
  1059. //allowMinimize:false,
  1060. //showStatusbar: false
  1061. });
  1062. this.Window.clientArea.setPadding(10);
  1063. this.Window.clientArea.setLayout(new qx.ui.layout.VBox(3));
  1064.  
  1065. this.Widget = new qx.ui.container.Composite(new qx.ui.layout.Grid().set({
  1066. spacingX: 5,
  1067. spacingY: 5
  1068. }));
  1069.  
  1070. //this.Widget.setTextColor("white");
  1071.  
  1072. this.Window.clientArea.add(this.Widget);
  1073. }
  1074.  
  1075. if (this.Window.isVisible()) {
  1076. this.Window.close();
  1077. } else {
  1078. MT_Base.openWindow(this.Window, WindowName);
  1079. this.setWidgetLabels();
  1080. }
  1081. } catch (e) {
  1082. console.log("MaelstromTools.Preferences.openWindow: ", e);
  1083. }
  1084. },
  1085.  
  1086. addFormElement: function (name, element) {
  1087. this.FormElements[name] = element;
  1088. },
  1089.  
  1090. setWidgetLabels: function () {
  1091. try {
  1092. this.readOptions();
  1093.  
  1094. this.FormElements = {};
  1095. this.Widget.removeAll();
  1096. var rowIdx = 1;
  1097. var colIdx = 1;
  1098.  
  1099. var chkAutoHideMissionTracker = new qx.ui.form.CheckBox(Lang.gt("Hide Mission Tracker")).set({
  1100. value: this.Settings[MaelstromTools.Preferences.AUTOHIDEMISSIONTRACKER] == 1
  1101. });
  1102. var chkUseDedicatedMainMenu = new qx.ui.form.CheckBox(Lang.gt("Use dedicated Main Menu (restart required)")).set({
  1103. value: this.Settings[MaelstromTools.Preferences.USEDEDICATEDMAINMENU] == 1
  1104. });
  1105. var chkShowLoot = new qx.ui.form.CheckBox(Lang.gt("Show lootable resources (restart required)")).set({
  1106. value: this.Settings[MaelstromTools.Preferences.SHOWLOOT] == 1/*,
  1107. enabled: CCTAWrapperIsInstalled()*/
  1108. });
  1109. var chkCostsNextMCV = new qx.ui.form.CheckBox(Lang.gt("Show time to next MCV")).set({
  1110. value: this.Settings[MaelstromTools.Preferences.SHOWCOSTSFORNEXTMCV] == 1
  1111. });
  1112. MaelstromTools.Util.addElement(this.Widget, rowIdx++, colIdx, chkAutoHideMissionTracker, 2);
  1113. MaelstromTools.Util.addElement(this.Widget, rowIdx++, colIdx, chkUseDedicatedMainMenu, 2);
  1114. MaelstromTools.Util.addElement(this.Widget, rowIdx++, colIdx, chkShowLoot, 2);
  1115. MaelstromTools.Util.addElement(this.Widget, rowIdx++, colIdx, chkCostsNextMCV, 2);
  1116.  
  1117. var chkAutoCollectPackages = new qx.ui.form.CheckBox(Lang.gt("Autocollect packages")).set({
  1118. value: this.Settings[MaelstromTools.Preferences.AUTOCOLLECTPACKAGES] == 1
  1119. });
  1120. var chkAutoRepairUnits = new qx.ui.form.CheckBox(Lang.gt("Autorepair units")).set({
  1121. value: this.Settings[MaelstromTools.Preferences.AUTOREPAIRUNITS] == 1,
  1122. enabled: CCTAWrapperIsInstalled()
  1123. });
  1124. var chkAutoRepairBuildings = new qx.ui.form.CheckBox(Lang.gt("Autorepair buildings")).set({
  1125. value: this.Settings[MaelstromTools.Preferences.AUTOREPAIRBUILDINGS] == 1,
  1126. enabled: CCTAWrapperIsInstalled()
  1127. });
  1128.  
  1129. var spinnerChatHistoryLength = new qx.ui.form.Spinner().set({
  1130. minimum: 64,
  1131. maximum: 512,
  1132. value: this.Settings[MaelstromTools.Preferences.CHATHISTORYLENGTH]
  1133. });
  1134.  
  1135. MaelstromTools.Util.addLabel(this.Widget, rowIdx, colIdx, Lang.gt("Chat history length") + " (" + spinnerChatHistoryLength.getMinimum() + " - " + spinnerChatHistoryLength.getMaximum() + ")");
  1136. MaelstromTools.Util.addElement(this.Widget, rowIdx++, colIdx + 1, spinnerChatHistoryLength);
  1137.  
  1138. var spinnerAutoCollectTimer = new qx.ui.form.Spinner().set({
  1139. minimum: 5,
  1140. maximum: 60 * 6,
  1141. value: this.Settings[MaelstromTools.Preferences.AUTOCOLLECTTIMER]
  1142. });
  1143.  
  1144. MaelstromTools.Util.addLabel(this.Widget, rowIdx, colIdx, Lang.gt("Automatic interval in minutes") + " (" + spinnerAutoCollectTimer.getMinimum() + " - " + spinnerAutoCollectTimer.getMaximum() + ")");
  1145. MaelstromTools.Util.addElement(this.Widget, rowIdx++, colIdx + 1, spinnerAutoCollectTimer);
  1146. MaelstromTools.Util.addElement(this.Widget, rowIdx++, colIdx, chkAutoCollectPackages, 2);
  1147. MaelstromTools.Util.addElement(this.Widget, rowIdx++, colIdx, chkAutoRepairUnits, 2);
  1148. MaelstromTools.Util.addElement(this.Widget, rowIdx++, colIdx, chkAutoRepairBuildings, 2);
  1149.  
  1150. var applyButton = new qx.ui.form.Button(Lang.gt("Apply changes")).set({
  1151. appearance: "button-addpoints",
  1152. width: 120,
  1153. minWidth: 120,
  1154. maxWidth: 120
  1155. });
  1156. applyButton.addListener("execute", this.applyChanges, this);
  1157.  
  1158. var cancelButton = new qx.ui.form.Button(Lang.gt("Discard changes")).set({
  1159. appearance: "button-addpoints",
  1160. width: 120,
  1161. minWidth: 120,
  1162. maxWidth: 120
  1163. });
  1164. cancelButton.addListener("execute", function () {
  1165. this.Window.close();
  1166. }, this);
  1167.  
  1168. var resetButton = new qx.ui.form.Button(Lang.gt("Reset to default")).set({
  1169. appearance: "button-addpoints",
  1170. width: 120,
  1171. minWidth: 120,
  1172. maxWidth: 120
  1173. });
  1174. resetButton.addListener("execute", this.resetToDefault, this);
  1175.  
  1176. MaelstromTools.Util.addElement(this.Widget, rowIdx++, colIdx, resetButton);
  1177. colIdx = 1;
  1178. MaelstromTools.Util.addElement(this.Widget, rowIdx, colIdx++, cancelButton);
  1179. MaelstromTools.Util.addElement(this.Widget, rowIdx++, colIdx, applyButton);
  1180.  
  1181. this.addFormElement(MaelstromTools.Preferences.AUTOHIDEMISSIONTRACKER, chkAutoHideMissionTracker);
  1182. this.addFormElement(MaelstromTools.Preferences.USEDEDICATEDMAINMENU, chkUseDedicatedMainMenu);
  1183. this.addFormElement(MaelstromTools.Preferences.SHOWLOOT, chkShowLoot);
  1184. this.addFormElement(MaelstromTools.Preferences.SHOWCOSTSFORNEXTMCV, chkCostsNextMCV);
  1185. this.addFormElement(MaelstromTools.Preferences.AUTOCOLLECTPACKAGES, chkAutoCollectPackages);
  1186. this.addFormElement(MaelstromTools.Preferences.AUTOREPAIRUNITS, chkAutoRepairUnits);
  1187. this.addFormElement(MaelstromTools.Preferences.AUTOREPAIRBUILDINGS, chkAutoRepairBuildings);
  1188. this.addFormElement(MaelstromTools.Preferences.AUTOCOLLECTTIMER, spinnerAutoCollectTimer);
  1189. this.addFormElement(MaelstromTools.Preferences.CHATHISTORYLENGTH, spinnerChatHistoryLength);
  1190. } catch (e) {
  1191. console.log("MaelstromTools.Preferences.setWidgetLabels: ", e);
  1192. }
  1193. },
  1194.  
  1195. applyChanges: function () {
  1196. try {
  1197. var autoRunNeeded = false;
  1198. for (var idx in this.FormElements) {
  1199. var element = this.FormElements[idx];
  1200. if (idx == MaelstromTools.Preferences.AUTOCOLLECTTIMER) {
  1201. autoRunNeeded = (MaelstromTools.LocalStorage.get(MaelstromTools.Preferences.AUTOCOLLECTTIMER, 0) != element.getValue());
  1202. }
  1203. if (idx == MaelstromTools.Preferences.CHATHISTORYLENGTH) {
  1204. webfrontend.gui.chat.ChatWidget.recvbufsize = element.getValue();
  1205. }
  1206. MaelstromTools.LocalStorage.set(idx, element.getValue());
  1207. }
  1208. this.readOptions();
  1209. if (autoRunNeeded) {
  1210. MT_Base.runAutoCollectTimer();
  1211. }
  1212. this.Window.close();
  1213. } catch (e) {
  1214. console.log("MaelstromTools.Preferences.applyChanges: ", e);
  1215. }
  1216. },
  1217.  
  1218. resetToDefault: function () {
  1219. try {
  1220. MaelstromTools.LocalStorage.clearAll();
  1221. this.setWidgetLabels();
  1222. } catch (e) {
  1223. console.log("MaelstromTools.Preferences.resetToDefault: ", e);
  1224. }
  1225. }
  1226. }
  1227. });
  1228.  
  1229. // define DefaultObject
  1230. qx.Class.define("MaelstromTools.DefaultObject", {
  1231. type: "abstract",
  1232. extend: qx.core.Object,
  1233. members: {
  1234. Window: null,
  1235. Widget: null,
  1236. Cache: {}, //k null
  1237. IsTimerEnabled: true,
  1238.  
  1239. calc: function () {
  1240. try {
  1241. if (this.Window.isVisible()) {
  1242. this.updateCache();
  1243. this.setWidgetLabels();
  1244. if (this.IsTimerEnabled) {
  1245. var self = this;
  1246. setTimeout(function () {
  1247. self.calc();
  1248. }, MT_Base.timerInterval);
  1249. }
  1250. }
  1251. } catch (e) {
  1252. console.log("MaelstromTools.DefaultObject.calc: ", e);
  1253. }
  1254. },
  1255.  
  1256. openWindow: function (WindowName, WindowTitle) {
  1257. try {
  1258. if (!this.Window) {
  1259. this.Window = new qx.ui.window.Window(WindowTitle).set({
  1260. resizable: false,
  1261. showMaximize: false,
  1262. showMinimize: false,
  1263. allowMaximize: false,
  1264. allowMinimize: false,
  1265. showStatusbar: false
  1266. });
  1267. this.Window.setPadding(10);
  1268. this.Window.setLayout(new qx.ui.layout.VBox(3));
  1269.  
  1270. this.Widget = new qx.ui.container.Composite(new qx.ui.layout.Grid());
  1271. this.Widget.setTextColor("white");
  1272.  
  1273. this.Window.add(this.Widget);
  1274. }
  1275.  
  1276. if (this.Window.isVisible()) {
  1277. this.Window.close();
  1278. } else {
  1279. MT_Base.openWindow(this.Window, WindowName);
  1280. this.calc();
  1281. }
  1282. } catch (e) {
  1283. console.log("MaelstromTools.DefaultObject.openWindow: ", e);
  1284. }
  1285. }
  1286. }
  1287. });
  1288.  
  1289. // define Production
  1290. qx.Class.define("MaelstromTools.Production", {
  1291. type: "singleton",
  1292. extend: MaelstromTools.DefaultObject,
  1293. members: {
  1294. RessiTech: null,
  1295. ressiCounter: function (obCity, resTypeToCount, resName) {
  1296. var retVal = 0;
  1297. var techDn = "Ressi";
  1298. try
  1299. {
  1300. for(var b in obCity.get_Buildings()['d'])
  1301. {
  1302. if(obCity.get_Buildings()['d'][b].get_CollectResourceType() === resTypeToCount)
  1303. {
  1304. retVal++;
  1305. techDn = obCity.get_Buildings()['d'][b].get_TechGameData_Obj()['dn']
  1306. if(this.RessiTech === null || this.RessiTech === undefined) this.RessiTech = Object();
  1307. //this.RessiTech[resTypeToCount] = techDn;
  1308. this.RessiTech[resName] = techDn;
  1309. }
  1310. }
  1311. }
  1312. catch(ex)
  1313. {
  1314. console.log("ressiCounter: " + ex.message);
  1315. }
  1316. //var o = Object();
  1317. //o['count'] = retVal;
  1318. //o['tech'] = techDn;
  1319. //o['resName'] = resName;
  1320. return retVal;
  1321. },
  1322. updateCache: function (onlyForCity) {
  1323. try {
  1324. MT_Cache.updateCityCache();
  1325. var alliance = ClientLib.Data.MainData.GetInstance().get_Alliance();
  1326. //this.Cache = Object();
  1327.  
  1328. for (var cname in MT_Cache.Cities) {
  1329. if (onlyForCity != null && onlyForCity != cname) {
  1330. continue;
  1331. }
  1332. var ncity = MT_Cache.Cities[cname].Object;
  1333. if (typeof (this.Cache[cname]) !== 'object') this.Cache[cname] = {};
  1334. if (typeof (this.Cache[cname][MaelstromTools.Statics.Tiberium]) !== 'object') this.Cache[cname][MaelstromTools.Statics.Tiberium] = {}; // all have to be checked,
  1335. if (typeof (this.Cache[cname][MaelstromTools.Statics.Crystal]) !== 'object') this.Cache[cname][MaelstromTools.Statics.Crystal] = {}; // this.Cache[cname] can be created inside different namespaces
  1336. if (typeof (this.Cache[cname][MaelstromTools.Statics.Power]) !== 'object') this.Cache[cname][MaelstromTools.Statics.Power] = {}; // like the RepairTime etc... without those objs
  1337. if (typeof (this.Cache[cname][MaelstromTools.Statics.Dollar]) !== 'object') this.Cache[cname][MaelstromTools.Statics.Dollar] = {};
  1338.  
  1339. //this.Cache[cname]["CityObj"] = ncity;
  1340. this.Cache[cname]["ProductionStopped"] = ncity.get_IsGhostMode();
  1341. this.Cache[cname]["PackagesStopped"] = (ncity.get_hasCooldown() || ncity.get_IsGhostMode());
  1342. this.Cache[cname][MaelstromTools.Statics.Tiberium]["Delta"] = ncity.GetResourceGrowPerHour(ClientLib.Base.EResourceType.Tiberium, false, false); // (production.d[ClientLib.Base.EResourceType.Tiberium]['Delta'] * serverTime.get_StepsPerHour());
  1343. this.Cache[cname][MaelstromTools.Statics.Tiberium]["ExtraBonusDelta"] = ncity.GetResourceBonusGrowPerHour(ClientLib.Base.EResourceType.Tiberium); //(production.d[ClientLib.Base.EResourceType.Tiberium]['ExtraBonusDelta'] * serverTime.get_StepsPerHour());
  1344. this.Cache[cname][MaelstromTools.Statics.Tiberium]["POI"] = alliance.GetPOIBonusFromResourceType(ClientLib.Base.EResourceType.Tiberium);
  1345. this.Cache[cname][MaelstromTools.Statics.Tiberium]["CollectBuildingCount"] = this.ressiCounter(ncity,ClientLib.Base.EResourceType.Tiberium,"Tiberium");
  1346. this.Cache[cname][MaelstromTools.Statics.Crystal]["Delta"] = ncity.GetResourceGrowPerHour(ClientLib.Base.EResourceType.Crystal, false, false); //(production.d[ClientLib.Base.EResourceType.Crystal]['Delta'] * serverTime.get_StepsPerHour());
  1347. this.Cache[cname][MaelstromTools.Statics.Crystal]["ExtraBonusDelta"] = ncity.GetResourceBonusGrowPerHour(ClientLib.Base.EResourceType.Crystal); //(production.d[ClientLib.Base.EResourceType.Crystal]['ExtraBonusDelta'] * serverTime.get_StepsPerHour());
  1348. this.Cache[cname][MaelstromTools.Statics.Crystal]["POI"] = alliance.GetPOIBonusFromResourceType(ClientLib.Base.EResourceType.Crystal);
  1349. this.Cache[cname][MaelstromTools.Statics.Crystal]["CollectBuildingCount"] = this.ressiCounter(ncity,ClientLib.Base.EResourceType.Crystal,"Crystal");
  1350.  
  1351. this.Cache[cname][MaelstromTools.Statics.Power]["Delta"] = ncity.GetResourceGrowPerHour(ClientLib.Base.EResourceType.Power, false, false); //(production.d[ClientLib.Base.EResourceType.Power]['Delta'] * serverTime.get_StepsPerHour());
  1352. this.Cache[cname][MaelstromTools.Statics.Power]["ExtraBonusDelta"] = ncity.GetResourceBonusGrowPerHour(ClientLib.Base.EResourceType.Power); // (production.d[ClientLib.Base.EResourceType.Power]['ExtraBonusDelta'] * serverTime.get_StepsPerHour());
  1353. this.Cache[cname][MaelstromTools.Statics.Power]["POI"] = alliance.GetPOIBonusFromResourceType(ClientLib.Base.EResourceType.Power);
  1354. this.Cache[cname][MaelstromTools.Statics.Power]["CollectBuildingCount"] = this.ressiCounter(ncity,ClientLib.Base.EResourceType.Power,"Power");
  1355.  
  1356. this.Cache[cname][MaelstromTools.Statics.Dollar]["Delta"] = ClientLib.Base.Resource.GetResourceGrowPerHour(ncity.get_CityCreditsProduction(), false); // (ncity.get_CityCreditsProduction()['Delta'] * serverTime.get_StepsPerHour());
  1357. this.Cache[cname][MaelstromTools.Statics.Dollar]["ExtraBonusDelta"] = ClientLib.Base.Resource.GetResourceBonusGrowPerHour(ncity.get_CityCreditsProduction(), false); // (ncity.get_CityCreditsProduction()['ExtraBonusDelta'] * serverTime.get_StepsPerHour());
  1358. this.Cache[cname][MaelstromTools.Statics.Dollar]["POI"] = 0;
  1359. this.Cache[cname][MaelstromTools.Statics.Dollar]["CollectBuildingCount"] = this.ressiCounter(ncity,ClientLib.Base.EResourceType.Gold,"Dollar");
  1360. this.Cache[cname]["BaseLevel"] = MaelstromTools.Wrapper.GetBaseLevel(ncity);
  1361. if (onlyForCity != null && onlyForCity == cname) return this.Cache[cname];
  1362. }
  1363. } catch (e) {
  1364. console.log("MaelstromTools.Production.updateCache: ", e);
  1365. }
  1366. },
  1367.  
  1368. createProductionLabels2: function (rowIdx, colIdx, cityName, resourceType) {
  1369. try {
  1370. var Totals = Object();
  1371. Totals["Felder"] = 0; //sammler count
  1372. Totals["Delta"] = 0;
  1373. Totals["ExtraBonusDelta"] = 0;
  1374. Totals["POI"] = 0;
  1375. Totals["Total"] = 0; // gesamt stunde
  1376. Totals["Total2"] = 0; // gesamt tag
  1377. Totals["Schnitt"] = 0; // gesamt tag sammler /felder
  1378.  
  1379. for (var cname in this.Cache) {
  1380. Totals["Felder"] += this.Cache[cname][resourceType]['CollectBuildingCount'];
  1381. Totals["Delta"] += this.Cache[cname][resourceType]['Delta'];
  1382. Totals["ExtraBonusDelta"] += this.Cache[cname][resourceType]['ExtraBonusDelta'];
  1383. Totals["POI"] += this.Cache[cname][resourceType]['POI'];
  1384. }
  1385. Totals["Total"] = Totals['Delta'] + Totals['ExtraBonusDelta'] + Totals['POI'];
  1386. Totals["Total2"] = Totals["Total"] * 24;
  1387. Totals["Schnitt"] = ((Totals["Delta"] + Totals["ExtraBonusDelta"]) * 24) / Totals["Felder"];
  1388.  
  1389. if (cityName == "-Total-") {
  1390.  
  1391. rowIdx++;
  1392. MaelstromTools.Util.addLabel(this.Widget, rowIdx++, colIdx, MaelstromTools.Wrapper.FormatNumbersCompact(Totals['Felder']), 80, 'right', 'bold');
  1393. MaelstromTools.Util.addLabel(this.Widget, rowIdx++, colIdx, MaelstromTools.Wrapper.FormatNumbersCompact(Totals['Schnitt']), 80, 'right', 'bold');
  1394. MaelstromTools.Util.addLabel(this.Widget, rowIdx++, colIdx, MaelstromTools.Wrapper.FormatNumbersCompact(Totals['Delta']), 80, 'right', 'bold');
  1395. MaelstromTools.Util.addLabel(this.Widget, rowIdx++, colIdx, MaelstromTools.Wrapper.FormatNumbersCompact(Totals['ExtraBonusDelta']), 80, 'right', 'bold');
  1396. if (resourceType != MaelstromTools.Statics.Dollar) {
  1397. MaelstromTools.Util.addLabel(this.Widget, rowIdx++, colIdx, MaelstromTools.Wrapper.FormatNumbersCompact(Totals['POI']), 80, 'right', 'bold');
  1398. } else {
  1399. rowIdx++;
  1400. }
  1401. MaelstromTools.Util.addLabel(this.Widget, rowIdx++, colIdx, MaelstromTools.Wrapper.FormatNumbersCompact(Totals['Total']), 80, 'right', 'bold');
  1402. MaelstromTools.Util.addLabel(this.Widget, rowIdx++, colIdx, MaelstromTools.Wrapper.FormatNumbersCompact(Totals['Total2']), 80, 'right', 'bold', "lightGreen");
  1403. } else if (cityName == "-Labels-") {
  1404. //console.log("--------> lege Labels an!");
  1405. //console.log("rowIdx: " + String(rowIdx) + " colIdx: " + String(colIdx) + " cityName: " + cityName + " resourceType: " + String(resourceType));
  1406. //console.log(this.RessiTech);
  1407. //console.log(this.Cache[cityName][resourceType]['CollectBuildingCount']);
  1408. MaelstromTools.Util.addImage(this.Widget, rowIdx++, colIdx, MaelstromTools.Util.getImage(resourceType));
  1409. //MaelstromTools.Util.addLabel(this.Widget, rowIdx++, colIdx, this.Cache[1][resourceType]['CollectBuildingCount']['tech'], 100, 'left');
  1410. MaelstromTools.Util.addLabel(this.Widget, rowIdx++, colIdx, this.RessiTech[resourceType], 100, 'left');
  1411. MaelstromTools.Util.addLabel(this.Widget, rowIdx++, colIdx, "Ø / d", 100, 'left');
  1412. MaelstromTools.Util.addLabel(this.Widget, rowIdx++, colIdx, "Continuous", 100, 'left');
  1413. MaelstromTools.Util.addLabel(this.Widget, rowIdx++, colIdx, "Bonus", 100, 'left');
  1414. if (resourceType != MaelstromTools.Statics.Dollar) {
  1415. MaelstromTools.Util.addLabel(this.Widget, rowIdx++, colIdx, "POI", 100, 'left');
  1416. } else {
  1417. MaelstromTools.Util.addLabel(this.Widget, rowIdx++, colIdx, "Total / BaseLevel", 100, 'left');
  1418. }
  1419. MaelstromTools.Util.addLabel(this.Widget, rowIdx++, colIdx, "Total / h", 100, 'left');
  1420. MaelstromTools.Util.addLabel(this.Widget, rowIdx++, colIdx, "Total / d", 100, 'left');
  1421. } else {
  1422. var cityCache = this.Cache[cityName];
  1423. if (rowIdx > 2) {
  1424. rowIdx++;
  1425. }
  1426. MaelstromTools.Util.addLabel(this.Widget, rowIdx++, colIdx, MaelstromTools.Wrapper.FormatNumbersCompact(cityCache[resourceType]['CollectBuildingCount']), 80, 'right'); //ANZAHL RESSI FELDER
  1427. var perFeld = ((cityCache[resourceType]['Delta'] + cityCache[resourceType]['ExtraBonusDelta']) * 24) / cityCache[resourceType]['CollectBuildingCount'];
  1428. MaelstromTools.Util.addLabel(this.Widget, rowIdx++, colIdx, MaelstromTools.Wrapper.FormatNumbersCompact(perFeld), 80, 'right', null, (perFeld >= Totals["Schnitt"]) ? "lightGreen" : "red");
  1429. MaelstromTools.Util.addLabel(this.Widget, rowIdx++, colIdx, MaelstromTools.Wrapper.FormatNumbersCompact(cityCache[resourceType]['Delta']), 80, 'right', null, ((cityCache["ProductionStopped"] || cityCache[resourceType]['Delta'] == 0) ? "red" : "white"));
  1430. MaelstromTools.Util.addLabel(this.Widget, rowIdx++, colIdx, MaelstromTools.Wrapper.FormatNumbersCompact(cityCache[resourceType]['ExtraBonusDelta']), 80, 'right', null, ((cityCache["PackagesStopped"] || cityCache[resourceType]['ExtraBonusDelta'] == 0) ? "red" : "white"));
  1431. if (resourceType != MaelstromTools.Statics.Dollar) {
  1432. MaelstromTools.Util.addLabel(this.Widget, rowIdx++, colIdx, MaelstromTools.Wrapper.FormatNumbersCompact(cityCache[resourceType]['POI']), 80, 'right', null, (cityCache[resourceType]['POI'] == 0 ? "red" : "white"));
  1433. } else {
  1434. MaelstromTools.Util.addLabel(this.Widget, rowIdx++, colIdx, MaelstromTools.Wrapper.FormatNumbersCompact((cityCache[resourceType]['Delta'] + cityCache[resourceType]['ExtraBonusDelta'] + cityCache[resourceType]['POI']) / cityCache["BaseLevel"]), 80, 'right');
  1435. }
  1436. MaelstromTools.Util.addLabel(this.Widget, rowIdx++, colIdx, MaelstromTools.Wrapper.FormatNumbersCompact(cityCache[resourceType]['Delta'] + cityCache[resourceType]['ExtraBonusDelta'] + cityCache[resourceType]['POI']), 80, 'right', 'bold');
  1437. MaelstromTools.Util.addLabel(this.Widget, rowIdx++, colIdx, MaelstromTools.Wrapper.FormatNumbersCompact((cityCache[resourceType]['Delta'] + cityCache[resourceType]['ExtraBonusDelta'] + cityCache[resourceType]['POI'])*24), 80, 'right', 'bold', "lightGreen");
  1438. }
  1439. return rowIdx;
  1440. } catch (e) {
  1441. console.log("MaelstromTools.Production.createProductionLabels2: ", e);
  1442. }
  1443. },
  1444.  
  1445. setWidgetLabels: function () {
  1446. try {
  1447. this.Widget.removeAll();
  1448. var rowIdx = 1;
  1449. var colIdx = 1;
  1450.  
  1451. rowIdx = this.createProductionLabels2(rowIdx, colIdx, "-Labels-", MaelstromTools.Statics.Tiberium);
  1452. rowIdx = this.createProductionLabels2(rowIdx, colIdx, "-Labels-", MaelstromTools.Statics.Crystal);
  1453. rowIdx = this.createProductionLabels2(rowIdx, colIdx, "-Labels-", MaelstromTools.Statics.Power);
  1454. rowIdx = this.createProductionLabels2(rowIdx, colIdx, "-Labels-", MaelstromTools.Statics.Dollar);
  1455.  
  1456. colIdx++;
  1457. for (var cityName in this.Cache) {
  1458. rowIdx = 1;
  1459. var lbl = MaelstromTools.Util.addLabel(this.Widget, rowIdx++, colIdx, cityName, 80, 'right', 'bold', "lightBlue");
  1460. if(lbl)
  1461. {
  1462. /*lbl.set({value: "test"});*/
  1463. }
  1464.  
  1465. rowIdx = this.createProductionLabels2(rowIdx, colIdx, cityName, MaelstromTools.Statics.Tiberium);
  1466. rowIdx = this.createProductionLabels2(rowIdx, colIdx, cityName, MaelstromTools.Statics.Crystal);
  1467. rowIdx = this.createProductionLabels2(rowIdx, colIdx, cityName, MaelstromTools.Statics.Power);
  1468. rowIdx = this.createProductionLabels2(rowIdx, colIdx, cityName, MaelstromTools.Statics.Dollar);
  1469.  
  1470. MaelstromTools.Util.addElement(this.Widget, rowIdx, colIdx++, MaelstromTools.Util.getAccessBaseButton(cityName));
  1471. }
  1472.  
  1473. rowIdx = 1;
  1474. MaelstromTools.Util.addLabel(this.Widget, rowIdx, colIdx, "Total", 80, 'right', 'bold', "lightBlue");
  1475. rowIdx = this.createProductionLabels2(rowIdx, colIdx, "-Total-", MaelstromTools.Statics.Tiberium);
  1476. rowIdx = this.createProductionLabels2(rowIdx, colIdx, "-Total-", MaelstromTools.Statics.Crystal);
  1477. rowIdx = this.createProductionLabels2(rowIdx, colIdx, "-Total-", MaelstromTools.Statics.Power);
  1478. rowIdx = this.createProductionLabels2(rowIdx, colIdx, "-Total-", MaelstromTools.Statics.Dollar);
  1479. } catch (e) {
  1480. console.log("MaelstromTools.Production.setWidgetLabels: ", e);
  1481. }
  1482. }
  1483. }
  1484. });
  1485.  
  1486. // define RepairTime
  1487. qx.Class.define("MaelstromTools.RepairTime", {
  1488. type: "singleton",
  1489. extend: MaelstromTools.DefaultObject,
  1490. members: {
  1491.  
  1492. updateCache: function () {
  1493. try {
  1494. MT_Cache.updateCityCache();
  1495. this.Cache = Object();
  1496.  
  1497. for (var cname in MT_Cache.Cities) {
  1498. var ncity = MT_Cache.Cities[cname].Object;
  1499. var RepLargest = '';
  1500.  
  1501. this.Cache[cname] = Object();
  1502. this.Cache[cname]["RepairTime"] = Object();
  1503. this.Cache[cname]["Repaircharge"] = Object();
  1504. this.Cache[cname]["Repaircharge"]["Smallest"] = 999999999;
  1505. this.Cache[cname]["RepairTime"]["Largest"] = 0;
  1506.  
  1507. this.Cache[cname]["RepairTime"][MaelstromTools.Statics.Infantry] = ncity.get_CityUnitsData().GetRepairTimeFromEUnitGroup(ClientLib.Data.EUnitGroup.Infantry, false);
  1508. this.Cache[cname]["RepairTime"][MaelstromTools.Statics.Vehicle] = ncity.get_CityUnitsData().GetRepairTimeFromEUnitGroup(ClientLib.Data.EUnitGroup.Vehicle, false);
  1509. this.Cache[cname]["RepairTime"][MaelstromTools.Statics.Aircraft] = ncity.get_CityUnitsData().GetRepairTimeFromEUnitGroup(ClientLib.Data.EUnitGroup.Aircraft, false);
  1510. this.Cache[cname]["RepairTime"]["Maximum"] = ncity.GetResourceMaxStorage(ClientLib.Base.EResourceType.RepairChargeInf);
  1511. this.Cache[cname]["Repaircharge"][MaelstromTools.Statics.Infantry] = ncity.GetResourceCount(ClientLib.Base.EResourceType.RepairChargeInf);
  1512. this.Cache[cname]["Repaircharge"][MaelstromTools.Statics.Vehicle] = ncity.GetResourceCount(ClientLib.Base.EResourceType.RepairChargeVeh);
  1513. this.Cache[cname]["Repaircharge"][MaelstromTools.Statics.Aircraft] = ncity.GetResourceCount(ClientLib.Base.EResourceType.RepairChargeAir);
  1514.  
  1515. if (this.Cache[cname]["Repaircharge"][MaelstromTools.Statics.Infantry] < this.Cache[cname]["Repaircharge"]["Smallest"]) {
  1516. this.Cache[cname]["Repaircharge"]["Smallest"] = this.Cache[cname]["Repaircharge"][MaelstromTools.Statics.Infantry];
  1517. }
  1518. if (this.Cache[cname]["Repaircharge"][MaelstromTools.Statics.Vehicle] < this.Cache[cname]["Repaircharge"]["Smallest"]) {
  1519. this.Cache[cname]["Repaircharge"]["Smallest"] = this.Cache[cname]["Repaircharge"][MaelstromTools.Statics.Vehicle];
  1520. }
  1521. if (this.Cache[cname]["Repaircharge"][MaelstromTools.Statics.Aircraft] < this.Cache[cname]["Repaircharge"]["Smallest"]) {
  1522. this.Cache[cname]["Repaircharge"]["Smallest"] = this.Cache[cname]["Repaircharge"][MaelstromTools.Statics.Aircraft];
  1523. }
  1524.  
  1525. if (this.Cache[cname]["RepairTime"][MaelstromTools.Statics.Infantry] > this.Cache[cname]["RepairTime"]["Largest"]) {
  1526. this.Cache[cname]["RepairTime"]["Largest"] = this.Cache[cname]["RepairTime"][MaelstromTools.Statics.Infantry];
  1527. RepLargest = "Infantry";
  1528. }
  1529. if (this.Cache[cname]["RepairTime"][MaelstromTools.Statics.Vehicle] > this.Cache[cname]["RepairTime"]["Largest"]) {
  1530. this.Cache[cname]["RepairTime"]["Largest"] = this.Cache[cname]["RepairTime"][MaelstromTools.Statics.Vehicle];
  1531. RepLargest = "Vehicle";
  1532. }
  1533. if (this.Cache[cname]["RepairTime"][MaelstromTools.Statics.Aircraft] > this.Cache[cname]["RepairTime"]["Largest"]) {
  1534. this.Cache[cname]["RepairTime"]["Largest"] = this.Cache[cname]["RepairTime"][MaelstromTools.Statics.Aircraft];
  1535. RepLargest = "Aircraft";
  1536. }
  1537.  
  1538. //PossibleAttacks and MaxAttacks fixes
  1539. var offHealth = ncity.GetOffenseConditionInPercent();
  1540. if (RepLargest !== '') {
  1541. this.Cache[cname]["RepairTime"]["LargestDiv"] = this.Cache[cname]["RepairTime"][RepLargest];
  1542. var i = Math.ceil(this.Cache[cname]["Repaircharge"].Smallest / this.Cache[cname]["RepairTime"].LargestDiv); //fix
  1543. var j = this.Cache[cname]["Repaircharge"].Smallest / this.Cache[cname]["RepairTime"].LargestDiv;
  1544. if (offHealth !== 100) { i--; i += '*';} // Decrease number of attacks by 1 when unit unhealthy. Additional visual info: asterisk when units aren't healthy
  1545. this.Cache[cname]["RepairTime"]["PossibleAttacks"] = i;
  1546. var k = this.Cache[cname]["RepairTime"].Maximum / this.Cache[cname]["RepairTime"].LargestDiv;
  1547. this.Cache[cname]["RepairTime"]["MaxAttacks"] = Math.ceil(k); //fix
  1548. } else {
  1549. this.Cache[cname]["RepairTime"]["LargestDiv"] = 0;
  1550. this.Cache[cname]["RepairTime"]["PossibleAttacks"] = 0;
  1551. this.Cache[cname]["RepairTime"]["MaxAttacks"] = 0;
  1552. }
  1553.  
  1554. var unitsData = ncity.get_CityUnitsData();
  1555. this.Cache[cname]["Base"] = Object();
  1556. this.Cache[cname]["Base"]["Level"] = MaelstromTools.Wrapper.GetBaseLevel(ncity);
  1557. this.Cache[cname]["Base"]["UnitLimit"] = ncity.GetBuildingSlotLimit(); //ncity.GetNumBuildings();
  1558. this.Cache[cname]["Base"]["TotalHeadCount"] = ncity.GetBuildingSlotCount();
  1559. this.Cache[cname]["Base"]["FreeHeadCount"] = this.Cache[cname]["Base"]["UnitLimit"] - this.Cache[cname]["Base"]["TotalHeadCount"];
  1560. this.Cache[cname]["Base"]["HealthInPercent"] = ncity.GetBuildingsConditionInPercent();
  1561.  
  1562. this.Cache[cname]["Offense"] = Object();
  1563. this.Cache[cname]["Offense"]["Level"] = (Math.floor(ncity.get_LvlOffense() * 100) / 100).toFixed(2);
  1564. this.Cache[cname]["Offense"]["UnitLimit"] = unitsData.get_UnitLimitOffense();
  1565. this.Cache[cname]["Offense"]["TotalHeadCount"] = unitsData.get_TotalOffenseHeadCount();
  1566. this.Cache[cname]["Offense"]["FreeHeadCount"] = unitsData.get_FreeOffenseHeadCount();
  1567. this.Cache[cname]["Offense"]["HealthInPercent"] = offHealth > 0 ? offHealth : 0;
  1568.  
  1569. this.Cache[cname]["Defense"] = Object();
  1570. this.Cache[cname]["Defense"]["Level"] = (Math.floor(ncity.get_LvlDefense() * 100) / 100).toFixed(2);
  1571. this.Cache[cname]["Defense"]["UnitLimit"] = unitsData.get_UnitLimitDefense();
  1572. this.Cache[cname]["Defense"]["TotalHeadCount"] = unitsData.get_TotalDefenseHeadCount();
  1573. this.Cache[cname]["Defense"]["FreeHeadCount"] = unitsData.get_FreeDefenseHeadCount();
  1574. this.Cache[cname]["Defense"]["HealthInPercent"] = ncity.GetDefenseConditionInPercent() > 0 ? ncity.GetDefenseConditionInPercent() : 0;
  1575.  
  1576. //console.log(ncity.get_CityUnitsData().get_UnitLimitOffense() + " / " + ncity.get_CityUnitsData().get_TotalOffenseHeadCount() + " = " + ncity.get_CityUnitsData().get_FreeOffenseHeadCount());
  1577. //console.log(ncity.get_CityUnitsData().get_UnitLimitDefense() + " / " + ncity.get_CityUnitsData().get_TotalDefenseHeadCount() + " = " + ncity.get_CityUnitsData().get_FreeDefenseHeadCount());
  1578. }
  1579. } catch (e) {
  1580. console.log("MaelstromTools.RepairTime.updateCache: ", e);
  1581. }
  1582. },
  1583.  
  1584. setWidgetLabels: function () {
  1585. try {
  1586. this.Widget.removeAll();
  1587. var rowIdx = 1;
  1588.  
  1589. rowIdx = this.createOverviewLabels(rowIdx);
  1590. rowIdx = this.createRepairchargeLabels(rowIdx);
  1591. } catch (e) {
  1592. console.log("MaelstromTools.RepairTime.setWidgetLabels: ", e);
  1593. }
  1594. },
  1595.  
  1596. createRepairchargeLabels: function (rowIdx) {
  1597. try {
  1598. var colIdx = 2;
  1599. MaelstromTools.Util.addLabel(this.Widget, rowIdx++, colIdx++, "Repaircharges", null, 'left', null, null, 3);
  1600. colIdx = 2;
  1601.  
  1602. MaelstromTools.Util.addLabel(this.Widget, rowIdx, colIdx++, MaelstromTools.Statics.Infantry, 60, 'right');
  1603. MaelstromTools.Util.addLabel(this.Widget, rowIdx, colIdx++, MaelstromTools.Statics.Vehicle, 60, 'right');
  1604. MaelstromTools.Util.addLabel(this.Widget, rowIdx, colIdx++, MaelstromTools.Statics.Aircraft, 60, 'right');
  1605. MaelstromTools.Util.addLabel(this.Widget, rowIdx, colIdx++, "Repairtime", 80, 'right');
  1606. MaelstromTools.Util.addLabel(this.Widget, rowIdx, colIdx++, "Attacks", 60, 'right');
  1607. MaelstromTools.Util.addLabel(this.Widget, rowIdx, colIdx++, "Next at", 80, 'right');
  1608. MaelstromTools.Util.addLabel(this.Widget, rowIdx, colIdx++, "Max+1 at", 80, 'right');
  1609.  
  1610. rowIdx++;
  1611. for (var cityName in this.Cache) {
  1612. var cityCache = this.Cache[cityName];
  1613. if (cityCache.Offense.UnitLimit == 0) {
  1614. continue;
  1615. }
  1616. colIdx = 1;
  1617. MaelstromTools.Util.addLabel(this.Widget, rowIdx, colIdx++, cityName, 80, 'left');
  1618.  
  1619. // Skip bases with no armies
  1620. if (cityCache.Offense.UnitLimit > 0) {
  1621. MaelstromTools.Util.addLabel(this.Widget, rowIdx, colIdx++, MaelstromTools.Wrapper.FormatTimespan(cityCache.RepairTime.Infantry), 60, 'right', null, (cityCache.RepairTime.Infantry == cityCache.RepairTime.LargestDiv ? "yellow" : "white"));
  1622. MaelstromTools.Util.addLabel(this.Widget, rowIdx, colIdx++, MaelstromTools.Wrapper.FormatTimespan(cityCache.RepairTime.Vehicle), 60, 'right', null, (cityCache.RepairTime.Vehicle == cityCache.RepairTime.LargestDiv ? "yellow" : "white"));
  1623. MaelstromTools.Util.addLabel(this.Widget, rowIdx, colIdx++, MaelstromTools.Wrapper.FormatTimespan(cityCache.RepairTime.Aircraft), 60, 'right', null, (cityCache.RepairTime.Aircraft == cityCache.RepairTime.LargestDiv ? "yellow" : "white"));
  1624. MaelstromTools.Util.addLabel(this.Widget, rowIdx, colIdx++, MaelstromTools.Wrapper.FormatTimespan(cityCache.Repaircharge.Smallest), 80, 'right');
  1625. MaelstromTools.Util.addLabel(this.Widget, rowIdx, colIdx++, cityCache.RepairTime.PossibleAttacks + " / " + cityCache.RepairTime.MaxAttacks, 60, 'right', null, (cityCache.Offense.HealthInPercent !== 100 ? 'red' : null)); // mark red when unhealthy
  1626. var i = cityCache.RepairTime.LargestDiv * cityCache.RepairTime.PossibleAttacks;
  1627. var j = cityCache.RepairTime.LargestDiv * cityCache.RepairTime.MaxAttacks;
  1628. (i>0) ? MaelstromTools.Util.addLabel(this.Widget, rowIdx, colIdx++, MaelstromTools.Wrapper.FormatTimespan(i), 80, 'right', null, (i > cityCache.RepairTime.Maximum ? "yellow" : "white")) : colIdx++; /// yellow if more than Maximum RT
  1629. (j>0) ? MaelstromTools.Util.addLabel(this.Widget, rowIdx, colIdx++, MaelstromTools.Wrapper.FormatTimespan(j), 80, 'right') : colIdx++;
  1630. } else {
  1631. colIdx += 7;
  1632. }
  1633.  
  1634. colIdx += 4;
  1635. MaelstromTools.Util.addElement(this.Widget, rowIdx, colIdx++, MaelstromTools.Util.getAccessBaseButton(cityName, PerforceChangelist >= 376877 ? ClientLib.Data.PlayerAreaViewMode.pavmPlayerOffense : webfrontend.gui.PlayArea.PlayArea.modes.EMode_PlayerOffense));
  1636. rowIdx += 2;
  1637. }
  1638.  
  1639. return rowIdx;
  1640. } catch (e) {
  1641. console.log("MaelstromTools.RepairTime.createRepairchargeLabels: ", e);
  1642. }
  1643. },
  1644.  
  1645. createOverviewLabels: function (rowIdx) {
  1646. try {
  1647. var colIdx = 2;
  1648.  
  1649. MaelstromTools.Util.addLabel(this.Widget, rowIdx, colIdx, "Base", 60, 'right');
  1650. colIdx += 3;
  1651. MaelstromTools.Util.addLabel(this.Widget, rowIdx, colIdx, "Defense", 60, 'right');
  1652. colIdx += 3;
  1653. MaelstromTools.Util.addLabel(this.Widget, rowIdx, colIdx, "Army", 60, 'right');
  1654.  
  1655. rowIdx++;
  1656. colIdx = 2;
  1657.  
  1658. MaelstromTools.Util.addLabel(this.Widget, rowIdx, colIdx++, "Level", 60, 'right');
  1659. MaelstromTools.Util.addLabel(this.Widget, rowIdx, colIdx++, "Buildings", 60, 'right');
  1660. MaelstromTools.Util.addLabel(this.Widget, rowIdx, colIdx++, "Health", 60, 'right');
  1661.  
  1662. MaelstromTools.Util.addLabel(this.Widget, rowIdx, colIdx++, "Level", 60, 'right');
  1663. MaelstromTools.Util.addLabel(this.Widget, rowIdx, colIdx++, "Buildings", 60, 'right');
  1664. MaelstromTools.Util.addLabel(this.Widget, rowIdx, colIdx++, "Health", 60, 'right');
  1665.  
  1666. MaelstromTools.Util.addLabel(this.Widget, rowIdx, colIdx++, "Level", 60, 'right');
  1667. MaelstromTools.Util.addLabel(this.Widget, rowIdx, colIdx++, "Units", 60, 'right');
  1668. MaelstromTools.Util.addLabel(this.Widget, rowIdx, colIdx++, "Health", 60, 'right');
  1669.  
  1670. rowIdx++;
  1671. for (var cityName in this.Cache) {
  1672. var cityCache = this.Cache[cityName];
  1673. colIdx = 1;
  1674.  
  1675. MaelstromTools.Util.addLabel(this.Widget, rowIdx, colIdx++, cityName, 80, 'left');
  1676.  
  1677. MaelstromTools.Util.addLabel(this.Widget, rowIdx, colIdx++, cityCache.Base.Level, 60, 'right');
  1678. MaelstromTools.Util.addLabel(this.Widget, rowIdx, colIdx++, cityCache.Base.TotalHeadCount + " / " + cityCache.Base.UnitLimit, 60, 'right', null, (cityCache.Base.FreeHeadCount >= 1 ? "red" : "white"));
  1679. MaelstromTools.Util.addLabel(this.Widget, rowIdx, colIdx++, cityCache.Base.HealthInPercent + "%", 60, 'right', null, (cityCache.Base.HealthInPercent < 25 ? "red" : (cityCache.Base.HealthInPercent < 100 ? "yellow" : "white")));
  1680.  
  1681. if (cityCache.Defense.UnitLimit > 0) {
  1682. MaelstromTools.Util.addLabel(this.Widget, rowIdx, colIdx++, cityCache.Defense.Level, 60, 'right');
  1683. MaelstromTools.Util.addLabel(this.Widget, rowIdx, colIdx++, cityCache.Defense.TotalHeadCount + " / " + cityCache.Defense.UnitLimit, 60, 'right', null, (cityCache.Defense.FreeHeadCount >= 5 ? "red" : (cityCache.Defense.FreeHeadCount >= 3 ? "yellow" : "white")));
  1684. MaelstromTools.Util.addLabel(this.Widget, rowIdx, colIdx++, cityCache.Defense.HealthInPercent + "%", 60, 'right', null, (cityCache.Defense.HealthInPercent < 25 ? "red" : (cityCache.Defense.HealthInPercent < 100 ? "yellow" : "white")));
  1685. } else {
  1686. colIdx += 3;
  1687. }
  1688.  
  1689. // Skip bases with no armies
  1690. if (cityCache.Offense.UnitLimit > 0) {
  1691. MaelstromTools.Util.addLabel(this.Widget, rowIdx, colIdx++, cityCache.Offense.Level, 60, 'right');
  1692. MaelstromTools.Util.addLabel(this.Widget, rowIdx, colIdx++, cityCache.Offense.TotalHeadCount + " / " + cityCache.Offense.UnitLimit, 60, 'right', null, (cityCache.Offense.FreeHeadCount >= 10 ? "red" : (cityCache.Offense.FreeHeadCount >= 5 ? "yellow" : "white")));
  1693. MaelstromTools.Util.addLabel(this.Widget, rowIdx, colIdx++, cityCache.Offense.HealthInPercent + "%", 60, 'right', null, (cityCache.Offense.HealthInPercent < 25 ? "red" : (cityCache.Offense.HealthInPercent < 100 ? "yellow" : "white")));
  1694. } else {
  1695. colIdx += 3;
  1696. }
  1697.  
  1698. MaelstromTools.Util.addElement(this.Widget, rowIdx, colIdx++, MaelstromTools.Util.getAccessBaseButton(cityName));
  1699. rowIdx += 2;
  1700. }
  1701. return rowIdx;
  1702. } catch (e) {
  1703. console.log("MaelstromTools.RepairTime.createOverviewLabels: ", e);
  1704. }
  1705. }
  1706.  
  1707. }
  1708. });
  1709.  
  1710. // define ResourceOverview
  1711. qx.Class.define("MaelstromTools.ResourceOverview", {
  1712. type: "singleton",
  1713. extend: MaelstromTools.DefaultObject,
  1714. members: {
  1715. Table: null,
  1716. Model: null,
  1717.  
  1718. updateCache: function () {
  1719. try {
  1720. MT_Cache.updateCityCache();
  1721. this.Cache = Object();
  1722.  
  1723. for (var cname in MT_Cache.Cities) {
  1724. var ncity = MT_Cache.Cities[cname].Object;
  1725. var mtime = ClientLib.Data.MainData.GetInstance().get_Time();
  1726.  
  1727. this.Cache[cname] = Object();
  1728. this.Cache[cname][MaelstromTools.Statics.Tiberium] = ncity.GetResourceCount(ClientLib.Base.EResourceType.Tiberium);
  1729. this.Cache[cname][MaelstromTools.Statics.Tiberium + "Max"] = ncity.GetResourceMaxStorage(ClientLib.Base.EResourceType.Tiberium);
  1730. this.Cache[cname][MaelstromTools.Statics.Tiberium + "Full"] = mtime.GetJSStepTime(ncity.GetResourceStorageFullStep(ClientLib.Base.EResourceType.Tiberium));
  1731. this.Cache[cname][MaelstromTools.Statics.Crystal] = ncity.GetResourceCount(ClientLib.Base.EResourceType.Crystal);
  1732. this.Cache[cname][MaelstromTools.Statics.Crystal + "Max"] = ncity.GetResourceMaxStorage(ClientLib.Base.EResourceType.Crystal);
  1733. this.Cache[cname][MaelstromTools.Statics.Crystal + "Full"] = mtime.GetJSStepTime(ncity.GetResourceStorageFullStep(ClientLib.Base.EResourceType.Crystal));
  1734. this.Cache[cname][MaelstromTools.Statics.Power] = ncity.GetResourceCount(ClientLib.Base.EResourceType.Power);
  1735. this.Cache[cname][MaelstromTools.Statics.Power + "Max"] = ncity.GetResourceMaxStorage(ClientLib.Base.EResourceType.Power);
  1736. this.Cache[cname][MaelstromTools.Statics.Power + "Full"] = mtime.GetJSStepTime(ncity.GetResourceStorageFullStep(ClientLib.Base.EResourceType.Power));
  1737. }
  1738.  
  1739. } catch (e) {
  1740. console.log("MaelstromTools.ResourceOverview.updateCache: ", e);
  1741. }
  1742. },
  1743. /*
  1744. setWidgetLabelsTable: function () {
  1745. try {
  1746. if (!this.Table) {
  1747. this.Widget.setLayout(new qx.ui.layout.HBox());
  1748.  
  1749. this.Model = new qx.ui.table.model.Simple();
  1750. this.Model.setColumns(["City", "Tib. Storage", "Tiberium", "Full", "Crystal", "Full", "Power", "Storage", "Full"]);
  1751. this.Table = new qx.ui.table.Table(this.Model);
  1752. this.Widget.add(this.Table, {
  1753. flex: 1
  1754. });
  1755. }
  1756.  
  1757. var Totals = Object();
  1758. Totals[MaelstromTools.Statics.Tiberium] = 0;
  1759. Totals[MaelstromTools.Statics.Crystal] = 0;
  1760. Totals[MaelstromTools.Statics.Power] = 0;
  1761. Totals[MaelstromTools.Statics.Tiberium + "Max"] = 0;
  1762. Totals[MaelstromTools.Statics.Power + "Max"] = 0;
  1763.  
  1764. var rowData = [];
  1765.  
  1766. for (var cityName in this.Cache) {
  1767. var cityCache = this.Cache[cityName];
  1768.  
  1769. Totals[MaelstromTools.Statics.Tiberium] += cityCache[MaelstromTools.Statics.Tiberium];
  1770. Totals[MaelstromTools.Statics.Crystal] += cityCache[MaelstromTools.Statics.Crystal];
  1771. Totals[MaelstromTools.Statics.Power] += cityCache[MaelstromTools.Statics.Power];
  1772. Totals[MaelstromTools.Statics.Tiberium + "Max"] += cityCache[MaelstromTools.Statics.Tiberium + 'Max'];
  1773. Totals[MaelstromTools.Statics.Power + "Max"] += cityCache[MaelstromTools.Statics.Power + 'Max'];
  1774.  
  1775. rowData.push([
  1776. cityName,
  1777. MaelstromTools.Wrapper.FormatNumbersCompact(cityCache[MaelstromTools.Statics.Tiberium + 'Max']),
  1778. MaelstromTools.Wrapper.FormatNumbersCompact(cityCache[MaelstromTools.Statics.Tiberium]),
  1779. MaelstromTools.Wrapper.GetDateTimeString(cityCache[MaelstromTools.Statics.Tiberium + 'Full']),
  1780. MaelstromTools.Wrapper.FormatNumbersCompact(cityCache[MaelstromTools.Statics.Crystal]),
  1781. MaelstromTools.Wrapper.GetDateTimeString(cityCache[MaelstromTools.Statics.Crystal + 'Full']),
  1782. MaelstromTools.Wrapper.FormatNumbersCompact(cityCache[MaelstromTools.Statics.Power]),
  1783. MaelstromTools.Wrapper.FormatNumbersCompact(cityCache[MaelstromTools.Statics.Power + 'Max']),
  1784. MaelstromTools.Wrapper.GetDateTimeString(cityCache[MaelstromTools.Statics.Power + 'Full'])
  1785. ]);
  1786. }
  1787. rowData.push([
  1788. 'Total resources',
  1789. MaelstromTools.Wrapper.FormatNumbersCompact(Totals[MaelstromTools.Statics.Tiberium + 'Max']),
  1790. MaelstromTools.Wrapper.FormatNumbersCompact(Totals[MaelstromTools.Statics.Tiberium]),
  1791. '',
  1792. MaelstromTools.Wrapper.FormatNumbersCompact(Totals[MaelstromTools.Statics.Crystal]),
  1793. '',
  1794. MaelstromTools.Wrapper.FormatNumbersCompact(Totals[MaelstromTools.Statics.Power]),
  1795. MaelstromTools.Wrapper.FormatNumbersCompact(Totals[MaelstromTools.Statics.Power + 'Max']),
  1796. ''
  1797. ]);
  1798.  
  1799. this.Model.setData(rowData);
  1800. } catch (e) {
  1801. console.log("MaelstromTools.ResourceOverview.setWidgetLabels: ", e);
  1802. }
  1803. },
  1804.  
  1805. */
  1806. setWidgetLabels: function () {
  1807. try {
  1808. this.Widget.removeAll();
  1809.  
  1810. var first = true;
  1811. var rowIdx = 2;
  1812. var Totals = Object();
  1813. var colIdx = 1;
  1814. Totals[MaelstromTools.Statics.Tiberium] = 0;
  1815. Totals[MaelstromTools.Statics.Crystal] = 0;
  1816. Totals[MaelstromTools.Statics.Power] = 0;
  1817. Totals[MaelstromTools.Statics.Tiberium + "Max"] = 0;
  1818. Totals[MaelstromTools.Statics.Power + "Max"] = 0;
  1819.  
  1820. for (var cityName in this.Cache) {
  1821. var cityCache = this.Cache[cityName];
  1822. Totals[MaelstromTools.Statics.Tiberium] += cityCache[MaelstromTools.Statics.Tiberium];
  1823. Totals[MaelstromTools.Statics.Crystal] += cityCache[MaelstromTools.Statics.Crystal];
  1824. Totals[MaelstromTools.Statics.Power] += cityCache[MaelstromTools.Statics.Power];
  1825. Totals[MaelstromTools.Statics.Tiberium + "Max"] += cityCache[MaelstromTools.Statics.Tiberium + 'Max'];
  1826. Totals[MaelstromTools.Statics.Power + "Max"] += cityCache[MaelstromTools.Statics.Power + 'Max'];
  1827.  
  1828. colIdx = 1;
  1829.  
  1830. MaelstromTools.Util.addLabel(this.Widget, rowIdx, colIdx++, cityName, 100, 'left');
  1831. if (first) {
  1832. MaelstromTools.Util.addLabel(this.Widget, 1, colIdx, 'Max. storage', 80, 'left');
  1833. }
  1834. MaelstromTools.Util.addLabel(this.Widget, rowIdx, colIdx++, MaelstromTools.Wrapper.FormatNumbersCompact(cityCache[MaelstromTools.Statics.Tiberium + 'Max']), 80, 'right');
  1835.  
  1836. if (first) {
  1837. MaelstromTools.Util.addImage(this.Widget, 1, colIdx, MaelstromTools.Util.getImage(MaelstromTools.Statics.Tiberium));
  1838. }
  1839. MaelstromTools.Util.addLabel(this.Widget, rowIdx, colIdx++, MaelstromTools.Wrapper.FormatNumbersCompact(cityCache[MaelstromTools.Statics.Tiberium]), 60, 'right', null, (cityCache[MaelstromTools.Statics.Tiberium] >= cityCache[MaelstromTools.Statics.Tiberium + 'Max'] ? "red" : (cityCache[MaelstromTools.Statics.Tiberium] >= (0.75 * cityCache[MaelstromTools.Statics.Tiberium + 'Max']) ? "yellow" : "white")));
  1840.  
  1841. if (cityCache[MaelstromTools.Statics.Tiberium] < cityCache[MaelstromTools.Statics.Tiberium + 'Max']) {
  1842. MaelstromTools.Util.addLabel(this.Widget, rowIdx, colIdx++, MaelstromTools.Wrapper.GetDateTimeString(cityCache[MaelstromTools.Statics.Tiberium + 'Full']), 100, 'right', null, (cityCache[MaelstromTools.Statics.Tiberium] >= (0.75 * cityCache[MaelstromTools.Statics.Tiberium + 'Max']) ? "yellow" : "white"));
  1843. } else {
  1844. MaelstromTools.Util.addLabel(this.Widget, rowIdx, colIdx++, "Storage full!", 100, 'right', null, "red");
  1845. }
  1846. if (first) {
  1847. MaelstromTools.Util.addImage(this.Widget, 1, colIdx, MaelstromTools.Util.getImage(MaelstromTools.Statics.Crystal));
  1848. }
  1849. MaelstromTools.Util.addLabel(this.Widget, rowIdx, colIdx++, MaelstromTools.Wrapper.FormatNumbersCompact(cityCache[MaelstromTools.Statics.Crystal]), 60, 'right', null, (cityCache[MaelstromTools.Statics.Crystal] >= cityCache[MaelstromTools.Statics.Crystal + 'Max'] ? "red" : (cityCache[MaelstromTools.Statics.Crystal] >= (0.75 * cityCache[MaelstromTools.Statics.Crystal + 'Max']) ? "yellow" : "white")));
  1850.  
  1851. if (cityCache[MaelstromTools.Statics.Crystal] < cityCache[MaelstromTools.Statics.Crystal + 'Max']) {
  1852. MaelstromTools.Util.addLabel(this.Widget, rowIdx, colIdx++, MaelstromTools.Wrapper.GetDateTimeString(cityCache[MaelstromTools.Statics.Crystal + 'Full']), 100, 'right', null, (cityCache[MaelstromTools.Statics.Crystal] >= (0.75 * cityCache[MaelstromTools.Statics.Crystal + 'Max']) ? "yellow" : "white"));
  1853. } else {
  1854. MaelstromTools.Util.addLabel(this.Widget, rowIdx, colIdx++, "Storage full!", 100, 'right', null, "red");
  1855. }
  1856.  
  1857. if (first) {
  1858. MaelstromTools.Util.addImage(this.Widget, 1, colIdx, MaelstromTools.Util.getImage(MaelstromTools.Statics.Power));
  1859. }
  1860. MaelstromTools.Util.addLabel(this.Widget, rowIdx, colIdx++, MaelstromTools.Wrapper.FormatNumbersCompact(cityCache[MaelstromTools.Statics.Power]), 60, 'right', null, (cityCache[MaelstromTools.Statics.Power] >= cityCache[MaelstromTools.Statics.Power + 'Max'] ? "red" : (cityCache[MaelstromTools.Statics.Power] >= (0.75 * cityCache[MaelstromTools.Statics.Power + 'Max']) ? "yellow" : "white")));
  1861.  
  1862. if (first) {
  1863. MaelstromTools.Util.addLabel(this.Widget, 1, colIdx, 'Storage', 80, 'left');
  1864. }
  1865. MaelstromTools.Util.addLabel(this.Widget, rowIdx, colIdx++, MaelstromTools.Wrapper.FormatNumbersCompact(cityCache[MaelstromTools.Statics.Power + 'Max']), 80, 'right');
  1866.  
  1867. if (cityCache[MaelstromTools.Statics.Power] < cityCache[MaelstromTools.Statics.Power + 'Max']) {
  1868. MaelstromTools.Util.addLabel(this.Widget, rowIdx, colIdx++, MaelstromTools.Wrapper.GetDateTimeString(cityCache[MaelstromTools.Statics.Power + 'Full']), 100, 'right', null, (cityCache[MaelstromTools.Statics.Power] >= (0.75 * cityCache[MaelstromTools.Statics.Power + 'Max']) ? "yellow" : "white"));
  1869. } else {
  1870. MaelstromTools.Util.addLabel(this.Widget, rowIdx, colIdx++, "Storage full!", 100, 'right', null, "red");
  1871. }
  1872.  
  1873.  
  1874. MaelstromTools.Util.addElement(this.Widget, rowIdx, colIdx++, MaelstromTools.Util.getAccessBaseButton(cityName));
  1875. rowIdx++;
  1876. first = false;
  1877. }
  1878.  
  1879. colIdx = 1;
  1880. MaelstromTools.Util.addLabel(this.Widget, rowIdx, colIdx++, "Total resources", 100, 'left', 'bold');
  1881. MaelstromTools.Util.addLabel(this.Widget, rowIdx, colIdx++, MaelstromTools.Wrapper.FormatNumbersCompact(Totals[MaelstromTools.Statics.Tiberium + 'Max']), 80, 'right', 'bold');
  1882. MaelstromTools.Util.addLabel(this.Widget, rowIdx, colIdx++, MaelstromTools.Wrapper.FormatNumbersCompact(Totals[MaelstromTools.Statics.Tiberium]), 60, 'right', 'bold');
  1883. MaelstromTools.Util.addLabel(this.Widget, rowIdx, colIdx++, Math.round(Totals[MaelstromTools.Statics.Tiberium] / Totals[MaelstromTools.Statics.Tiberium + 'Max'] * 100) + '%', 100, 'center', 'bold');
  1884. MaelstromTools.Util.addLabel(this.Widget, rowIdx, colIdx++, MaelstromTools.Wrapper.FormatNumbersCompact(Totals[MaelstromTools.Statics.Crystal]), 60, 'right', 'bold');
  1885. MaelstromTools.Util.addLabel(this.Widget, rowIdx, colIdx++, Math.round(Totals[MaelstromTools.Statics.Crystal] / Totals[MaelstromTools.Statics.Tiberium + 'Max'] * 100) + '%', 100, 'center', 'bold');
  1886. MaelstromTools.Util.addLabel(this.Widget, rowIdx, colIdx++, MaelstromTools.Wrapper.FormatNumbersCompact(Totals[MaelstromTools.Statics.Power]), 60, 'right', 'bold');
  1887. MaelstromTools.Util.addLabel(this.Widget, rowIdx, colIdx++, MaelstromTools.Wrapper.FormatNumbersCompact(Totals[MaelstromTools.Statics.Power + 'Max']), 80, 'right', 'bold');
  1888. MaelstromTools.Util.addLabel(this.Widget, rowIdx, colIdx++, Math.round(Totals[MaelstromTools.Statics.Power] / Totals[MaelstromTools.Statics.Power + 'Max'] * 100) + '%', 100, 'center', 'bold');
  1889. } catch (e) {
  1890. console.log("MaelstromTools.ResourceOverview.setWidgetLabels: ", e);
  1891. }
  1892. }
  1893. }
  1894. });
  1895.  
  1896. // define BaseStatus
  1897. qx.Class.define("MaelstromTools.BaseStatus", {
  1898. type: "singleton",
  1899. extend: MaelstromTools.DefaultObject,
  1900. members: {
  1901. CityMenuButtons: null,
  1902.  
  1903. //City.SetDedicatedSupport
  1904. //City.RecallDedicatedSupport
  1905. //City.get_SupportDedicatedBaseId
  1906. //System.String get_SupportDedicatedBaseName ()
  1907. updateCache: function () {
  1908. try {
  1909. MT_Cache.updateCityCache();
  1910. this.Cache = Object();
  1911.  
  1912. for (var cname in MT_Cache.Cities) {
  1913. var ncity = MT_Cache.Cities[cname].Object;
  1914. var player = ClientLib.Data.MainData.GetInstance().get_Player();
  1915. var supportData = ncity.get_SupportData();
  1916. //System.String get_PlayerName ()
  1917. this.Cache[cname] = Object();
  1918. // Movement lock
  1919. this.Cache[cname]["HasCooldown"] = ncity.get_hasCooldown();
  1920. this.Cache[cname]["CooldownEnd"] = Math.max(ncity.get_MoveCooldownEndStep(), ncity.get_MoveRestictionEndStep());
  1921. this.Cache[cname]["MoveCooldownEnd"] = ncity.get_MoveCooldownEndStep();
  1922. this.Cache[cname]["MoveLockdownEnd"] = ncity.get_MoveRestictionEndStep();
  1923. this.Cache[cname]["IsProtected"] = ncity.get_isProtected();
  1924. this.Cache[cname]["ProtectionEnd"] = ncity.get_ProtectionEndStep();
  1925. this.Cache[cname]["IsProtected"] = ncity.get_ProtectionEndStep();
  1926. this.Cache[cname]["IsAlerted"] = ncity.get_isAlerted();
  1927.  
  1928. // Supportweapon
  1929. if (supportData == null) {
  1930. this.Cache[cname]["HasSupportWeapon"] = false;
  1931. } else {
  1932. this.Cache[cname]["HasSupportWeapon"] = true;
  1933. if (ncity.get_SupportDedicatedBaseId() > 0) {
  1934. this.Cache[cname]["SupportedCityId"] = ncity.get_SupportDedicatedBaseId();
  1935. this.Cache[cname]["SupportedCityName"] = ncity.get_SupportDedicatedBaseName();
  1936. var coordId = ncity.get_SupportDedicatedBaseCoordId();
  1937. this.Cache[cname]["SupportedCityX"] = (coordId & 0xffff);
  1938. this.Cache[cname]["SupportedCityY"] = ((coordId >> 0x10) & 0xffff);
  1939. /*
  1940. var cityX = ncity.get_PosX();
  1941. var cityY = ncity.get_PosY();
  1942. var mainData = ClientLib.Data.MainData.GetInstance();
  1943. var visRegion = ClientLib.Vis.VisMain.GetInstance().get_Region();
  1944.  
  1945. var gridW = visRegion.get_GridWidth();
  1946. var gridH = visRegion.get_GridHeight();
  1947. //console.log(cname);
  1948. //console.log("x: " + cityX + " y: " + cityY);
  1949.  
  1950. var worldObj = visRegion.GetObjectFromPosition((this.Cache[cname]["SupportedCityX"]*gridW), (this.Cache[cname]["SupportedCityY"]*gridH));
  1951. //ClientLib.Vis.Region.RegionCity
  1952. if (worldObj == null) {
  1953. this.Cache[cname]["SupportTime"] = "";
  1954. } else {
  1955. console.log(cname);
  1956. //console.log(worldObj.CalibrationSupportDuration());
  1957. var weaponState = worldObj.get_SupportWeaponStatus();
  1958. //console.log(this.calcDuration(ncity, worldObj));
  1959. var cities = ClientLib.Data.MainData.GetInstance().get_Cities();
  1960. cities.set_CurrentOwnCityId(ncity.get_Id());
  1961. var status = worldObj.get_SupportWeaponStatus();
  1962. var server = mainData.get_Server();
  1963. //console.log(worldObj.CalculateSupportCalibrationEndStep(worldObj.get_SupportData(), worldObj.get_SupportWeapon()));
  1964. console.log(status);
  1965. console.log(currStep);
  1966. this.Cache[cname]["SupportTime"] = mainData.get_Time().GetTimespanString(worldObj.CalculateSupportCalibrationEndStep(worldObj.get_SupportData(), worldObj.get_SupportWeapon()), currStep);
  1967. //status.Status&ClientLib.Vis.Region.ESupportWeaponStatus.Calibrating)==ClientLib.Vis.Region.ESupportWeaponStatus.Calibrating
  1968. var currStep = ClientLib.Data.MainData.GetInstance().get_Time().GetServerStep();
  1969. //this.Cache[cname]["SupportTime"] = webfrontend.Util.getTimespanString(ClientLib.Data.MainData.GetInstance().get_Time().GetTimeSpan(Math.max(0, status.CalibrationEndStep) - currStep), false);
  1970. //this.Cache[cname]["SupportTime"] = ClientLib.Data.MainData.GetInstance().get_Time().GetTimespanString(weaponState.CalibrationEndStep, currStep);
  1971. //this.Cache[cname]["SupportTime"] = webfrontend.Util.getTimespanString(ClientLib.Data.MainData.GetInstance().get_Time().GetTimeSpan(Math.max(0, worldObj.CalculateSupportCalibrationEndStep(worldObj.get_SupportData(), worldObj.get_SupportWeapon()) - currStep)), false);
  1972. //console.log(this.Cache[cname]["SupportTime"]);
  1973. }
  1974. */
  1975. } else { // prevent reference to undefined property ReferenceError
  1976. this.Cache[cname]["SupportedCityId"] = null;
  1977. this.Cache[cname]["SupportedCityName"] = null;
  1978. this.Cache[cname]["SupportedCityX"] = null;
  1979. this.Cache[cname]["SupportedCityY"] = null;
  1980. }
  1981. this.Cache[cname]["SupportRange"] = MaelstromTools.Wrapper.GetSupportWeaponRange(ncity.get_SupportWeapon());
  1982. var techName = ClientLib.Base.Tech.GetTechNameFromTechId(supportData.get_Type(), player.get_Faction());
  1983. this.Cache[cname]["SupportName"] = ClientLib.Base.Tech.GetProductionBuildingNameFromFaction(techName, player.get_Faction());
  1984. this.Cache[cname]["SupportLevel"] = supportData.get_Level();
  1985. //this.Cache[cname]["SupportBuilding"] = ncity.get_CityBuildingsData().GetUniqueBuildingByTechName(techName);
  1986. //console.log(this.Cache[cname]["SupportBuilding"]);
  1987. }
  1988. }
  1989. } catch (e) {
  1990. console.log("MaelstromTools.BaseStatus.updateCache: ", e);
  1991. }
  1992. },
  1993. /*
  1994. calcDuration: function(currOwnCity, regionCity) {
  1995. var targetCity = MaelstromTools.Wrapper.GetCity(regionCity.get_Id());
  1996. var supportBase=regionCity.get_SupportData();
  1997. if(supportBase == null)
  1998. {
  1999. return -1;
  2000. }
  2001. var weapon=regionCity.get_SupportWeapon();
  2002. if(weapon == null)
  2003. {
  2004. return -1;
  2005. }
  2006. if(currOwnCity.get_Id() == regionCity.get_Id())
  2007. {
  2008. if(supportBase.get_Magnitude() == 0) {
  2009. return -1;
  2010. }
  2011. return 0;
  2012. }
  2013. var dx=(currOwnCity.get_X() - targetCity.get_PosX());
  2014. var dy=(currOwnCity.get_Y() - targetCity.get_PosY());
  2015. var distance=((dx * dx) + (dy * dy));
  2016. return Math.floor((weapon.pt + (weapon.tpf * Math.floor((Math.sqrt(distance) + 0.5)))));
  2017. },*/
  2018.  
  2019. setWidgetLabels: function () {
  2020. try {
  2021. this.Widget.removeAll();
  2022. var rowIdx = 1;
  2023. var colIdx = 2;
  2024.  
  2025. MaelstromTools.Util.addLabel(this.Widget, rowIdx, colIdx++, "Cooldown", 85, 'left');
  2026. MaelstromTools.Util.addLabel(this.Widget, rowIdx, colIdx++, "Protection", 85, 'left');
  2027. MaelstromTools.Util.addLabel(this.Widget, rowIdx, colIdx++, "Available weapon", 140, 'left');
  2028. MaelstromTools.Util.addLabel(this.Widget, rowIdx, colIdx++, "Calibrated on", 140, 'left');
  2029.  
  2030. //colIdx++;
  2031. var rowIdxRecall = rowIdx;
  2032. var colIdxRecall = 0;
  2033. var supportWeaponCount = 0;
  2034.  
  2035. rowIdx++;
  2036. for (var cityName in this.Cache) {
  2037. var cityCache = this.Cache[cityName];
  2038. colIdx = 1;
  2039.  
  2040. MaelstromTools.Util.addLabel(this.Widget, rowIdx, colIdx++, cityName, 100, 'left', null, (cityCache.IsAlerted ? 'red' : null));
  2041.  
  2042. MaelstromTools.Util.addLabel(this.Widget, rowIdx, colIdx++, MaelstromTools.Wrapper.GetStepTime(cityCache.CooldownEnd), 70, 'right');
  2043. MaelstromTools.Util.addLabel(this.Widget, rowIdx, colIdx++, MaelstromTools.Wrapper.GetStepTime(cityCache.ProtectionEnd), 70, 'right');
  2044.  
  2045. if (!cityCache.HasSupportWeapon) {
  2046. MaelstromTools.Util.addLabel(this.Widget, rowIdx, colIdx++, "none", 140, 'left');
  2047. colIdx += 2;
  2048. } else {
  2049. supportWeaponCount++;
  2050. MaelstromTools.Util.addLabel(this.Widget, rowIdx, colIdx++, cityCache.SupportName + " (" + cityCache.SupportLevel + ")", 140, 'left');
  2051.  
  2052. if (cityCache.SupportedCityId > 0) {
  2053. MaelstromTools.Util.addLabel(this.Widget, rowIdx, colIdx++, cityCache.SupportedCityName, 140, 'left');
  2054. colIdxRecall = colIdx;
  2055. MaelstromTools.Util.addElement(this.Widget, rowIdx, colIdx++, this.getRecallButton(cityName));
  2056. } else {
  2057. colIdx += 2;
  2058. }
  2059. }
  2060.  
  2061. MaelstromTools.Util.addElement(this.Widget, rowIdx, colIdx++, MaelstromTools.Util.getAccessBaseButton(cityName));
  2062. MaelstromTools.Util.addElement(this.Widget, rowIdx, colIdx++, MaelstromTools.Util.getFocusBaseButton(cityName));
  2063.  
  2064. rowIdx++;
  2065. }
  2066.  
  2067. if (supportWeaponCount > 0 && colIdxRecall > 0) {
  2068. MaelstromTools.Util.addElement(this.Widget, rowIdxRecall, colIdxRecall, this.getRecallAllButton());
  2069. }
  2070. } catch (e) {
  2071. console.log("MaelstromTools.BaseStatus.setWidgetLabels: ", e);
  2072. }
  2073. },
  2074.  
  2075. getRecallAllButton: function () {
  2076. var button = new qx.ui.form.Button("Recall all").set({
  2077. appearance: "button-text-small",
  2078. toolTipText: "Recall all support weapons",
  2079. width: 100,
  2080. height: 20
  2081. });
  2082. button.addListener("execute", function (e) {
  2083. MaelstromTools.Util.recallAllSupport();
  2084. }, this);
  2085. return button;
  2086. },
  2087.  
  2088. getRecallButton: function (cityName) {
  2089. var button = new qx.ui.form.Button("Recall").set({
  2090. appearance: "button-text-small",
  2091. toolTipText: "Recall support to " + cityName,
  2092. width: 100,
  2093. height: 20
  2094. });
  2095. button.addListener("execute", function (e) {
  2096. MaelstromTools.Util.recallSupport(cityName);
  2097. }, this);
  2098. return button;
  2099. }
  2100. /*
  2101. getCalibrateAllOnSelectedBaseButton: function() {
  2102. var button = new qx.ui.form.Button("Calibrate all weapons on selected base").set({
  2103. appearance: "button-text-small",
  2104. toolTipText: "Calibrate all weapons",
  2105. width: 100,
  2106. height: 20
  2107. });
  2108. button.addListener("execute", function(e){
  2109. Util.calibrateWholeSupport(ClientLib.Data.MainData.GetInstance().get_Cities().get_CurrentCityId());
  2110. }, this);
  2111. return button;
  2112. }*/
  2113.  
  2114.  
  2115. }
  2116. });
  2117.  
  2118. // define Statics
  2119. qx.Class.define("MaelstromTools.Statics", {
  2120. type: "static",
  2121. statics: {
  2122. Tiberium: 'Tiberium',
  2123. Crystal: 'Crystal',
  2124. Power: 'Power',
  2125. Dollar: 'Dollar',
  2126. Research: 'Research',
  2127. Vehicle: "Vehicle",
  2128. Aircraft: "Aircraft",
  2129. Infantry: "Infantry",
  2130.  
  2131. LootTypeName: function (ltype) {
  2132. switch (ltype) {
  2133. case ClientLib.Base.EResourceType.Tiberium:
  2134. return MaelstromTools.Statics.Tiberium;
  2135. break;
  2136. case ClientLib.Base.EResourceType.Crystal:
  2137. return MaelstromTools.Statics.Crystal;
  2138. break;
  2139. case ClientLib.Base.EResourceType.Power:
  2140. return MaelstromTools.Statics.Power;
  2141. break;
  2142. case ClientLib.Base.EResourceType.Gold:
  2143. return MaelstromTools.Statics.Dollar;
  2144. break;
  2145. default:
  2146. return "";
  2147. break;
  2148. }
  2149. }
  2150. }
  2151. });
  2152.  
  2153. // define Util
  2154. //ClientLib.Data.Cities.prototype.GetCityByCoord
  2155. //ClientLib.Data.City.prototype.get_HasIncommingAttack
  2156. qx.Class.define("MaelstromTools.Util", {
  2157. type: "static",
  2158. statics: {
  2159. ArrayUnique: function (array) {
  2160. var o = {};
  2161. var l = array.length;
  2162. r = [];
  2163. for (var i = 0; i < l; i++) o[array[i]] = array[i];
  2164. for (var i in o) r.push(o[i]);
  2165. return r;
  2166. },
  2167.  
  2168. ArraySize: function (array) {
  2169. var size = 0;
  2170. for (var key in array)
  2171. if (array.hasOwnProperty(key)) size++;
  2172. return size;
  2173. },
  2174.  
  2175. addLabel: function (widget, rowIdx, colIdx, value, width, textAlign, font, color, colSpan) {
  2176. try {
  2177. var label = new qx.ui.basic.Label().set({
  2178. value: Lang.gt(value),
  2179. rich: true
  2180. });
  2181. if (width) {
  2182. label.setWidth(width);
  2183. }
  2184. if (textAlign) {
  2185. label.setTextAlign(textAlign);
  2186. }
  2187. if (color) {
  2188. label.setTextColor(color);
  2189. }
  2190. if (font) {
  2191. label.setFont(font);
  2192. }
  2193. if (!colSpan || colSpan == 0) {
  2194. colSpan = 1;
  2195. }
  2196.  
  2197. widget.add(label, {
  2198. row: rowIdx,
  2199. column: colIdx,
  2200. colSpan: colSpan
  2201. });
  2202. return label;
  2203. } catch (e) {
  2204. console.log("MaelstromTools.Util.addLabel: ", e);
  2205. }
  2206. },
  2207.  
  2208. addElement: function (widget, rowIdx, colIdx, element, colSpan) {
  2209. try {
  2210. if (!colSpan || colSpan == 0) {
  2211. colSpan = 1;
  2212. }
  2213. widget.add(element, {
  2214. row: rowIdx,
  2215. column: colIdx,
  2216. colSpan: colSpan
  2217. });
  2218. } catch (e) {
  2219. console.log("MaelstromTools.Util.addElement: ", e);
  2220. }
  2221. },
  2222.  
  2223. addImage: function (widget, rowIdx, colIdx, image) {
  2224. try {
  2225. widget.add(image, {
  2226. row: rowIdx,
  2227. column: colIdx
  2228. });
  2229. } catch (e) {
  2230. console.log("MaelstromTools.Util.addImage: ", e);
  2231. }
  2232. },
  2233.  
  2234. getImage: function (name) {
  2235. var image = new qx.ui.basic.Image(MT_Base.images[name]);
  2236. image.setScale(true);
  2237. image.setWidth(20);
  2238. image.setHeight(20);
  2239. return image;
  2240. },
  2241.  
  2242. getAccessBaseButton: function (cityName, viewMode) {
  2243. try {
  2244. var cityButton = new qx.ui.form.Button(null, MT_Base.images["AccessBase"]).set({
  2245. appearance: "button-addpoints",
  2246. toolTipText: Lang.gt("Access") + " " + cityName,
  2247. width: 20,
  2248. height: 20,
  2249. marginLeft: 5
  2250. });
  2251. cityButton.setUserData("cityId", MT_Cache.Cities[cityName].ID);
  2252. cityButton.setUserData("viewMode", viewMode);
  2253. cityButton.addListener("execute", function (e) {
  2254. MaelstromTools.Util.accessBase(e.getTarget().getUserData("cityId"), e.getTarget().getUserData("viewMode"));
  2255. }, this);
  2256. return cityButton;
  2257. } catch (e) {
  2258. console.log("MaelstromTools.Util.getAccessBaseButton: ", e);
  2259. }
  2260. },
  2261.  
  2262. getFocusBaseButton: function (cityName) {
  2263. try {
  2264. var cityButton = new qx.ui.form.Button(null, MT_Base.images["FocusBase"]).set({
  2265. appearance: "button-addpoints",
  2266. toolTipText: Lang.gt("Focus on") + " " + cityName,
  2267. width: 20,
  2268. height: 20,
  2269. marginLeft: 5
  2270. });
  2271. cityButton.setUserData("cityId", MT_Cache.Cities[cityName].ID);
  2272. cityButton.addListener("execute", function (e) {
  2273. MaelstromTools.Util.focusBase(e.getTarget().getUserData("cityId"));
  2274. }, this);
  2275. return cityButton;
  2276. } catch (e) {
  2277. console.log("MaelstromTools.Util.getFocusBaseButton: ", e);
  2278. }
  2279. },
  2280.  
  2281. accessBase: function (cityId, viewMode) {
  2282. try {
  2283. if (cityId > 0) {
  2284. var ncity = MaelstromTools.Wrapper.GetCity(cityId);
  2285.  
  2286. if (ncity != null && !ncity.get_IsGhostMode()) {
  2287. if (viewMode) {
  2288. webfrontend.gui.UtilView.openVisModeInMainWindow(viewMode, cityId, false);
  2289. } else {
  2290. webfrontend.gui.UtilView.openCityInMainWindow(cityId);
  2291. }
  2292. }
  2293. }
  2294. } catch (e) {
  2295. console.log("MaelstromTools.Util.accessBase: ", e);
  2296. }
  2297. },
  2298. focusBase: function (cityId) {
  2299. try {
  2300. if (cityId > 0) {
  2301. var ncity = MaelstromTools.Wrapper.GetCity(cityId);
  2302.  
  2303. if (ncity != null && !ncity.get_IsGhostMode()) {
  2304. webfrontend.gui.UtilView.centerCityOnRegionViewWindow(cityId);
  2305. }
  2306. }
  2307. } catch (e) {
  2308. console.log("MaelstromTools.Util.focusBase: ", e);
  2309. }
  2310. },
  2311.  
  2312. recallSupport: function (cityName) {
  2313. try {
  2314. var ncity = MT_Cache.Cities[cityName]["Object"];
  2315. ncity.RecallDedicatedSupport();
  2316. } catch (e) {
  2317. console.log("MaelstromTools.Util.recallSupport: ", e);
  2318. }
  2319. },
  2320.  
  2321. recallAllSupport: function () {
  2322. try {
  2323. MT_Cache.updateCityCache();
  2324. for (var cityName in MT_Cache.Cities) {
  2325. var ncity = MT_Cache.Cities[cityName]["Object"];
  2326. ncity.RecallDedicatedSupport();
  2327. }
  2328. } catch (e) {
  2329. console.log("MaelstromTools.Util.recallAllSupport: ", e);
  2330. }
  2331. },
  2332.  
  2333. checkIfSupportIsAllowed: function (selectedBase) {
  2334. try {
  2335. if (selectedBase.get_VisObjectType() != ClientLib.Vis.VisObject.EObjectType.RegionCityType) {
  2336. return false;
  2337. }
  2338. if (selectedBase.get_Type() != ClientLib.Vis.Region.RegionCity.ERegionCityType.Own && selectedBase.get_Type() != ClientLib.Vis.Region.RegionCity.ERegionCityType.Alliance) {
  2339. return false;
  2340. }
  2341. return true;
  2342. } catch (e) {
  2343. console.log("MaelstromTools.Util.checkIfSupportIsAllowed: ", e);
  2344. return false;
  2345. }
  2346. },
  2347.  
  2348. calibrateWholeSupportOnSelectedBase: function () {
  2349. if (this.checkIfSupportIsAllowed(MT_Cache.SelectedBaseForMenu)) {
  2350. this.calibrateWholeSupport(MT_Cache.SelectedBaseForMenu);
  2351. }
  2352. },
  2353.  
  2354. calibrateWholeSupport: function (targetRegionCity) {
  2355. try {
  2356. MT_Cache.updateCityCache();
  2357. for (var cityName in MT_Cache.Cities) {
  2358. var ncity = MT_Cache.Cities[cityName]["Object"];
  2359. //var targetCity = MaelstromTools.Wrapper.GetCity(targetCityId);
  2360. var weapon = ncity.get_SupportWeapon();
  2361.  
  2362. //console.log("checking support weapon for " + ncity.get_Name() + " calibrating on " + targetRegionCity.get_Name());
  2363.  
  2364. if (targetRegionCity != null && weapon != null) {
  2365. //console.log("city at " + ncity.get_X() + " / " + ncity.get_Y());
  2366. //console.log("targetRegionCity at " + targetRegionCity.get_RawX() + " / " + targetRegionCity.get_RawY());
  2367. //var distance = ClientLib.Base.Util.CalculateDistance(ncity.get_X(), ncity.get_Y(), targetRegionCity.get_RawX(), targetRegionCity.get_RawY());
  2368. var dx = (ncity.get_X() - targetRegionCity.get_RawX());
  2369. var dy = (ncity.get_Y() - targetRegionCity.get_RawY());
  2370. var distance = ((dx * dx) + (dy * dy));
  2371. var range = MaelstromTools.Wrapper.GetSupportWeaponRange(weapon);
  2372. //console.log("distance is " + distance);
  2373. //console.log("range isy " + range*range);
  2374. if (distance <= (range * range)) {
  2375. ncity.SetDedicatedSupport(targetRegionCity.get_Id());
  2376. }
  2377. }
  2378. }
  2379. } catch (e) {
  2380. console.log("MaelstromTools.Util.calibrateWholeSupport: ", e);
  2381. }
  2382. },
  2383.  
  2384. // visCity : ClientLib.Vis.Region.RegionObject
  2385. getResources: function (visCity) { // to verifier against PerforceChangelist>=376877
  2386. try {
  2387. var loot = {};
  2388. if (visCity.get_X() < 0 || visCity.get_Y() < 0) {
  2389. loot["LoadState"] = 0;
  2390. return loot;
  2391. }
  2392. var currentOwnCity = ClientLib.Data.MainData.GetInstance().get_Cities().get_CurrentOwnCity();
  2393.  
  2394. var distance = ClientLib.Base.Util.CalculateDistance(currentOwnCity.get_X(), currentOwnCity.get_Y(), visCity.get_RawX(), visCity.get_RawY());
  2395. var maxAttackDistance = ClientLib.Data.MainData.GetInstance().get_Server().get_MaxAttackDistance();
  2396. if (distance > maxAttackDistance) {
  2397. loot["LoadState"] = -1;
  2398. return loot;
  2399. }
  2400.  
  2401. var ncity = MaelstromTools.Wrapper.GetCity(visCity.get_Id());
  2402. /* ClientLib.Data.CityBuildings */
  2403. //var cityBuildings = ncity.get_CityBuildingsData();
  2404. var cityUnits = ncity.get_CityUnitsData();
  2405.  
  2406. //var buildings = MaelstromTools.Wrapper.GetBuildings(cityBuildings);
  2407. var buildings = ncity.get_Buildings().d;
  2408. var defenseUnits = MaelstromTools.Wrapper.GetDefenseUnits(cityUnits);
  2409. //var defenseUnits = MaelstromTools.Wrapper.GetDefenseUnits();
  2410.  
  2411. /*for(var u in buildings) {
  2412. console.log(buildings[u].get_MdbBuildingId());
  2413. console.log("----------------");
  2414. }*/
  2415.  
  2416. var buildingLoot = MaelstromTools.Util.getResourcesPart(buildings);
  2417. //var buildingLoot2 = MaelstromTools.Util.getResourcesPart(this.collectBuildings(ncity));
  2418.  
  2419. var unitLoot = MaelstromTools.Util.getResourcesPart(defenseUnits);
  2420.  
  2421. loot[MaelstromTools.Statics.Tiberium] = buildingLoot[ClientLib.Base.EResourceType.Tiberium] + unitLoot[ClientLib.Base.EResourceType.Tiberium];
  2422. loot[MaelstromTools.Statics.Crystal] = buildingLoot[ClientLib.Base.EResourceType.Crystal] + unitLoot[ClientLib.Base.EResourceType.Crystal];
  2423. loot[MaelstromTools.Statics.Dollar] = buildingLoot[ClientLib.Base.EResourceType.Gold] + unitLoot[ClientLib.Base.EResourceType.Gold];
  2424. loot[MaelstromTools.Statics.Research] = buildingLoot[ClientLib.Base.EResourceType.ResearchPoints] + unitLoot[ClientLib.Base.EResourceType.ResearchPoints];
  2425. loot["Factor"] = loot[MaelstromTools.Statics.Tiberium] + loot[MaelstromTools.Statics.Crystal] + loot[MaelstromTools.Statics.Dollar] + loot[MaelstromTools.Statics.Research];
  2426. loot["CPNeeded"] = currentOwnCity.CalculateAttackCommandPointCostToCoord(ncity.get_X(), ncity.get_Y());
  2427. loot["LoadState"] = (loot["Factor"] > 0 ? 1 : 0);
  2428. loot["Total"] = loot[MaelstromTools.Statics.Research] + loot[MaelstromTools.Statics.Tiberium] + loot[MaelstromTools.Statics.Crystal] + loot[MaelstromTools.Statics.Dollar];
  2429.  
  2430. /*console.log("Building loot");
  2431. console.log( buildingLoot[ClientLib.Base.EResourceType.Tiberium] + " vs " + buildingLoot2[ClientLib.Base.EResourceType.Tiberium]);
  2432. console.log( buildingLoot[ClientLib.Base.EResourceType.Crystal] + " vs " + buildingLoot2[ClientLib.Base.EResourceType.Crystal]);
  2433. console.log( buildingLoot[ClientLib.Base.EResourceType.Gold] + " vs " + buildingLoot2[ClientLib.Base.EResourceType.Gold]);
  2434. console.log( buildingLoot[ClientLib.Base.EResourceType.ResearchPoints] + " vs " + buildingLoot2[ClientLib.Base.EResourceType.ResearchPoints]);
  2435. console.log("-------------");*/
  2436. return loot;
  2437. } catch (e) {
  2438. console.log("MaelstromTools.Util.getResources", e);
  2439. }
  2440. },
  2441. /*
  2442. collectBuildings: function(ncity) {
  2443. var cityBuildings = ncity.get_CityBuildingsData();
  2444. var buildings = [];
  2445. var count = 0;
  2446. // ncity.GetNumBuildings()
  2447. for(var i = 0; i < 100000; i++) {
  2448. var building = cityBuildings.GetBuildingByMDBId(i);
  2449. if(!building) {
  2450. continue;
  2451. }
  2452. //console.log(building.get_TechName() + " - " + ncity.get_CityFaction() + " - " + ClientLib.Base.Tech.GetTechIdFromTechNameAndFaction(building.get_TechName(), ncity.get_CityFaction()) + " at lvl " + building.get_CurrentLevel());
  2453. buildings.push(building);
  2454. //buildings[count++] = building;
  2455. }
  2456. return buildings; //MaelstromTools.Util.ArrayUnique(buildings);
  2457. },*/
  2458.  
  2459. getResourcesPart: function (cityEntities) {
  2460. try {
  2461. var loot = [0, 0, 0, 0, 0, 0, 0, 0];
  2462. if (cityEntities == null) {
  2463. return loot;
  2464. }
  2465.  
  2466. var objcityEntities = [];
  2467. if (PerforceChangelist >= 376877) { //new
  2468. for (var o in cityEntities) objcityEntities.push(cityEntities[o]);
  2469. } else { //old
  2470. for (var i = 0; i < cityEntities.length; i++) objcityEntities.push(cityEntities[i]);
  2471. }
  2472.  
  2473. for (var i = 0; i < objcityEntities.length; i++) {
  2474. var cityEntity = objcityEntities[i];
  2475. var unitLevelRequirements = MaelstromTools.Wrapper.GetUnitLevelRequirements(cityEntity);
  2476.  
  2477. for (var x = 0; x < unitLevelRequirements.length; x++) {
  2478. loot[unitLevelRequirements[x].Type] += unitLevelRequirements[x].Count * cityEntity.get_HitpointsPercent();
  2479. if (cityEntity.get_HitpointsPercent() < 1.0) {
  2480. // destroyed
  2481.  
  2482. }
  2483. }
  2484. }
  2485.  
  2486. return loot;
  2487. } catch (e) {
  2488. console.log("MaelstromTools.Util.getResourcesPart", e);
  2489. }
  2490. }
  2491.  
  2492. /*
  2493. findBuildings: function(city) {
  2494. for (var k in city) {
  2495. if ((typeof(city[k]) == "object") && city[k] && city[k] && 0 in city[k]) {
  2496. if ((typeof(city[k][0]) == "object") && city[k][0] && "BuildingDBId" in city[k][0]) {
  2497. return city[k];
  2498. }
  2499. }
  2500. }
  2501. return [];
  2502. }*/
  2503. }
  2504. });
  2505.  
  2506. // define Wrapper
  2507. qx.Class.define("MaelstromTools.Wrapper", {
  2508. type: "static",
  2509. statics: {
  2510. GetStepTime: function (step, defaultString) {
  2511. if (!defaultString) {
  2512. defaultString = "";
  2513. }
  2514. var endTime = ClientLib.Data.MainData.GetInstance().get_Time().GetTimespanString(step, ClientLib.Data.MainData.GetInstance().get_Time().GetServerStep());
  2515. if (endTime == "00:00") {
  2516. return defaultString;
  2517. }
  2518. return endTime;
  2519. },
  2520.  
  2521. FormatNumbersCompact: function (value) {
  2522. if (PerforceChangelist >= 387751) { //new
  2523. return phe.cnc.gui.util.Numbers.formatNumbersCompact(value);
  2524. } else { //old
  2525. return webfrontend.gui.Util.formatNumbersCompact(value);
  2526. }
  2527. },
  2528.  
  2529. GetDateTimeString: function (value) {
  2530. return phe.cnc.Util.getDateTimeString(value);
  2531. },
  2532.  
  2533. FormatTimespan: function (value) {
  2534. return ClientLib.Vis.VisMain.FormatTimespan(value);
  2535. },
  2536.  
  2537. GetSupportWeaponRange: function (weapon) {
  2538. return weapon.r;
  2539. },
  2540.  
  2541. GetCity: function (cityId) {
  2542. return ClientLib.Data.MainData.GetInstance().get_Cities().GetCity(cityId);
  2543. },
  2544.  
  2545. GetDefenseUnits: function (cityUnits) {
  2546. //GetDefenseUnits: function () {
  2547. if (PerforceChangelist >= 392583) { //endgame patch
  2548. return (cityUnits.get_DefenseUnits() != null ? cityUnits.get_DefenseUnits().d : null);
  2549. } else { //old
  2550. var defenseObjects = [];
  2551. for (var x = 0; x < 9; x++) {
  2552. for (var y = 0; y < 8; y++) {
  2553. var defenseObject = ClientLib.Vis.VisMain.GetInstance().get_DefenseSetup().GetDefenseObjectFromPosition((x * ClientLib.Vis.VisMain.GetInstance().get_City().get_GridWidth()),(y * ClientLib.Vis.VisMain.GetInstance().get_City().get_GridHeight()));
  2554. if (defenseObject !== null && defenseObject.get_CityEntity() !== null) {
  2555. defenseObjects.push(defenseObject.get_UnitDetails());
  2556. }
  2557. }
  2558. }
  2559. return defenseObjects;
  2560. }
  2561. },
  2562. GetUnitLevelRequirements: function (cityEntity) {
  2563. if (PerforceChangelist >= 376877) { //new
  2564. return (cityEntity.get_UnitLevelRepairRequirements() != null ? cityEntity.get_UnitLevelRepairRequirements() : null);
  2565. } else { //old
  2566. return (cityEntity.get_UnitLevelRequirements() != null ? cityEntity.get_UnitLevelRequirements() : null);
  2567. }
  2568. },
  2569.  
  2570. GetBaseLevel: function (ncity) {
  2571. return (Math.floor(ncity.get_LvlBase() * 100) / 100).toFixed(2);
  2572. }
  2573. /*,
  2574. GetPointsByLevelWithThresholds: function (_levelThresholds,_levelFactors,_iLevel) {
  2575. var result=0;
  2576. var lastLevel=_iLevel;
  2577. if(_levelThresholds.length != _levelFactors.length) {
  2578. return 0;
  2579. }
  2580. for (var i=(_levelThresholds.length - 1); (i >= 0); i--) {
  2581. var threshold=(_levelThresholds[i] - 1);
  2582. if(lastLevel >= threshold) {
  2583. result += ((lastLevel - threshold) * _levelFactors[i]);
  2584. lastLevel=threshold;
  2585. }
  2586. }
  2587. return result;
  2588. },
  2589. GetArmyPoints: function(_iLevel) {
  2590. var server = ClientLib.Data.MainData.GetInstance().get_Server();
  2591. var m_iArmyPointsPerLevelThresholds = server.get_ArmyPointsPerLevelThresholds();
  2592. var m_fArmyPointsPerLevel = server.get_ArmyPointsPerLevel();
  2593. _iLevel += 4;
  2594. var armyPoints = MaelstromTools.Wrapper.GetPointsByLevelWithThresholds(m_iArmyPointsPerLevelThresholds, m_fArmyPointsPerLevel, _iLevel);
  2595. return Math.min(armyPoints, server.get_MaxArmyPoints());
  2596. },
  2597. GetBuilding: function(ncity, techName) {
  2598. return ncity.get_CityBuildingsData().GetUniqueBuildingByTechName(techName)
  2599. },
  2600. GetCommandCenter: function(ncity) {
  2601. //var techName = ClientLib.Base.Tech.GetTechIdFromTechNameAndFaction(ClientLib.Base.ETechName.Command_Center, ClientLib.Data.MainData.GetInstance().get_Player().get_Faction());
  2602.  
  2603. return MaelstromTools.Wrapper.GetBuilding(ncity, ClientLib.Base.ETechName.Command_Center);
  2604. // conyard return this.GetBuildingCondition$0(ClientLib.Base.Tech.GetTechIdFromTechNameAndFaction$0(0, ClientLib.Data.MainData.GetInstance$9().get_Player$2().get_Faction$2()));
  2605. // ClientLib.Data.City.prototype.GetOffenseConditionInPercent=ClientLib.Data.City.prototype.GetOffenseConditionInPercent$0;
  2606. }*/
  2607. }
  2608. });
  2609.  
  2610. // define LocalStorage
  2611. qx.Class.define("MaelstromTools.LocalStorage", {
  2612. type: "static",
  2613. statics: {
  2614. isSupported: function () {
  2615. return typeof (Storage) !== "undefined";
  2616. },
  2617. set: function (key, value) {
  2618. try {
  2619. if (MaelstromTools.LocalStorage.isSupported()) {
  2620. localStorage["CCTA_MaelstromTools_" + key] = JSON.stringify(value);
  2621. }
  2622. } catch (e) {
  2623. console.log("MaelstromTools.LocalStorage.set: ", e);
  2624. }
  2625. },
  2626. get: function (key, defaultValueIfNotSet) {
  2627. try {
  2628. if (MaelstromTools.LocalStorage.isSupported()) {
  2629. if (localStorage["CCTA_MaelstromTools_" + key] != null && localStorage["CCTA_MaelstromTools_" + key] != 'undefined') {
  2630. return JSON.parse(localStorage["CCTA_MaelstromTools_" + key]);
  2631. }
  2632. }
  2633. } catch (e) {
  2634. console.log("MaelstromTools.LocalStorage.get: ", e);
  2635. }
  2636. return defaultValueIfNotSet;
  2637. },
  2638. clearAll: function () {
  2639. try {
  2640. if (!MaelstromTools.LocalStorage.isSupported()) {
  2641. return;
  2642. }
  2643. for (var key in localStorage) {
  2644. if (key.indexOf("CCTA_MaelstromTools_") == 0) {
  2645. localStorage.removeItem(key);
  2646. }
  2647. }
  2648. } catch (e) {
  2649. console.log("MaelstromTools.LocalStorage.clearAll: ", e);
  2650. }
  2651. }
  2652. }
  2653. });
  2654.  
  2655. // define Cache
  2656. qx.Class.define("MaelstromTools.Cache", {
  2657. type: "singleton",
  2658. extend: qx.core.Object,
  2659. members: {
  2660. CityCount: 0,
  2661. Cities: null,
  2662. SelectedBaseForMenu: null,
  2663. SelectedBaseResources: null,
  2664. SelectedBaseForLoot: null,
  2665.  
  2666. updateCityCache: function () {
  2667. try {
  2668. this.CityCount = 0;
  2669. this.Cities = Object();
  2670.  
  2671. var cities = ClientLib.Data.MainData.GetInstance().get_Cities().get_AllCities();
  2672. for (var cindex in cities.d) {
  2673. this.CityCount++;
  2674. var ncity = MaelstromTools.Wrapper.GetCity(cindex);
  2675. var ncityName = ncity.get_Name();
  2676. this.Cities[ncityName] = Object();
  2677. this.Cities[ncityName]["ID"] = cindex;
  2678. this.Cities[ncityName]["Object"] = ncity;
  2679. }
  2680. } catch (e) {
  2681. console.log("MaelstromTools.Cache.updateCityCache: ", e);
  2682. }
  2683. },
  2684.  
  2685. updateLoot: function (visCity) {
  2686. var cityId = visCity.get_Id();
  2687.  
  2688. if (this.SelectedBaseForLoot != null && cityId == this.SelectedBaseForLoot.get_Id() && this.SelectedBaseResources != null && this.SelectedBaseResources["LoadState"] > 0) {
  2689. return -2;
  2690. }
  2691. this.SelectedBaseForLoot = visCity;
  2692. this.SelectedBaseResources = MaelstromTools.Util.getResources(visCity);
  2693. return this.SelectedBaseResources["LoadState"];
  2694. }
  2695. }
  2696. });
  2697.  
  2698. // define HuffyTools.ImageRender
  2699. qx.Class.define("HuffyTools.ImageRender", {
  2700. extend: qx.ui.table.cellrenderer.AbstractImage,
  2701. construct: function (width, height) {
  2702. this.base(arguments);
  2703. if (width) {
  2704. this.__imageWidth = width;
  2705. }
  2706. if (height) {
  2707. this.__imageHeight = height;
  2708. }
  2709. this.__am = qx.util.AliasManager.getInstance();
  2710. },
  2711. members: {
  2712. __am: null,
  2713. __imageHeight: 16,
  2714. __imageWidth: 16,
  2715. // overridden
  2716. _identifyImage: function (cellInfo) {
  2717. var imageHints = {
  2718. imageWidth: this.__imageWidth,
  2719. imageHeight: this.__imageHeight
  2720. };
  2721. if (cellInfo.value == "") {
  2722. imageHints.url = null;
  2723. } else {
  2724. imageHints.url = this.__am.resolve(cellInfo.value);
  2725. }
  2726. imageHints.tooltip = cellInfo.tooltip;
  2727. return imageHints;
  2728. }
  2729. },
  2730. destruct: function () {
  2731. this.__am = null;
  2732. }
  2733. });
  2734.  
  2735. // define HuffyTools.ReplaceRender
  2736. qx.Class.define("HuffyTools.ReplaceRender", {
  2737. extend: qx.ui.table.cellrenderer.Default,
  2738. properties: {
  2739. replaceFunction: {
  2740. check: "Function",
  2741. nullable: true,
  2742. init: null
  2743. }
  2744. },
  2745. members: {
  2746. // overridden
  2747. _getContentHtml: function (cellInfo) {
  2748. var value = cellInfo.value;
  2749. var replaceFunc = this.getReplaceFunction();
  2750. // use function
  2751. if (replaceFunc) {
  2752. cellInfo.value = replaceFunc(value);
  2753. }
  2754. return qx.bom.String.escape(this._formatValue(cellInfo));
  2755. }
  2756. }
  2757. });
  2758.  
  2759. qx.Class.define("HuffyTools.CityCheckBox", {
  2760. extend: qx.ui.form.CheckBox,
  2761. members: {
  2762. HT_CityID: null
  2763. }
  2764. });
  2765.  
  2766. // define HuffyTools.UpgradePriorityGUI
  2767. qx.Class.define("HuffyTools.UpgradePriorityGUI", {
  2768. type: "singleton",
  2769. extend: MaelstromTools.DefaultObject,
  2770. members: {
  2771. HT_TabView: null,
  2772. HT_Options: null,
  2773. HT_ShowOnlyTopBuildings: null,
  2774. HT_ShowOnlyAffordableBuildings: null,
  2775. HT_CityBuildings: null,
  2776. HT_Pages: null,
  2777. HT_Tables: null,
  2778. HT_Models: null,
  2779. HT_SelectedResourceType: null,
  2780. BuildingList: null,
  2781. upgradeInProgress: null,
  2782. upgradeToDoType: null,
  2783. upgradeToDo: null,
  2784. init: function () {
  2785. /*
  2786. Done:
  2787. - Added cost per gain to the lists
  2788. - Added building coordinates to the lists
  2789. - Only display the top affordable and not affordable building
  2790. - Persistent filter by city, top and affordable per resource type
  2791. - Reload onTabChange for speed optimization
  2792. - Estimated time until upgrade is affordable
  2793. ToDo:
  2794. - let the user decide to sort by colums he like i.e. timefactor or cost/gain and save it in the configuration
  2795. - integrate buttons to transfer resources ?
  2796.  
  2797. */
  2798. try {
  2799. this.HT_SelectedResourceType = -1;
  2800. this.IsTimerEnabled = false;
  2801. this.upgradeInProgress = false;
  2802.  
  2803. this.HT_TabView = new qx.ui.tabview.TabView();
  2804. this.HT_TabView.set({
  2805. contentPadding: 0,
  2806. appearance: "tabview",
  2807. margin: 5,
  2808. barPosition: 'left'
  2809. });
  2810. this.Widget = new qx.ui.tabview.Page("UpgradePriority");
  2811. this.Widget.setPadding(0);
  2812. this.Widget.setMargin(0);
  2813. this.Widget.setBackgroundColor("#BEC8CF");
  2814. this.Widget.setLayout(new qx.ui.layout.VBox(2));
  2815. //this.Widget.add(this.HT_Options);
  2816. this.Widget.add(this.HT_TabView, {
  2817. flex: 1
  2818. });
  2819. this.Window.setPadding(0);
  2820. this.Window.set({
  2821. resizable: true
  2822. });
  2823.  
  2824. this.Window.removeAll();
  2825. this.Window.add(this.Widget);
  2826.  
  2827. this.BuildingList = [];
  2828. this.HT_Models = [];
  2829. this.HT_Tables = [];
  2830. this.HT_Pages = [];
  2831.  
  2832. if (PerforceChangelist >= 436669) { // 15.3 patch
  2833. var eventType = "cellTap";
  2834. } else { //old
  2835. var eventType = "cellClick";
  2836. }
  2837. this.createTabPage(ClientLib.Base.EResourceType.Tiberium);
  2838. this.createTable(ClientLib.Base.EResourceType.Tiberium);
  2839. this.HT_Tables[ClientLib.Base.EResourceType.Tiberium].addListener(eventType, function (e) {
  2840. this.upgradeBuilding(e, ClientLib.Base.EResourceType.Tiberium);
  2841. }, this);
  2842.  
  2843.  
  2844. this.createTabPage(ClientLib.Base.EResourceType.Crystal);
  2845. this.createTable(ClientLib.Base.EResourceType.Crystal);
  2846. this.HT_Tables[ClientLib.Base.EResourceType.Crystal].addListener(eventType, function (e) {
  2847. this.upgradeBuilding(e, ClientLib.Base.EResourceType.Crystal);
  2848. }, this);
  2849.  
  2850. this.createTabPage(ClientLib.Base.EResourceType.Power);
  2851. this.createTable(ClientLib.Base.EResourceType.Power);
  2852. this.HT_Tables[ClientLib.Base.EResourceType.Power].addListener(eventType, function (e) {
  2853. this.upgradeBuilding(e, ClientLib.Base.EResourceType.Power);
  2854. }, this);
  2855.  
  2856. this.createTabPage(ClientLib.Base.EResourceType.Gold);
  2857. this.createTable(ClientLib.Base.EResourceType.Gold);
  2858. this.HT_Tables[ClientLib.Base.EResourceType.Gold].addListener(eventType, function (e) {
  2859. this.upgradeBuilding(e, ClientLib.Base.EResourceType.Gold);
  2860. }, this);
  2861.  
  2862.  
  2863. MT_Cache.updateCityCache();
  2864. this.HT_Options = [];
  2865. this.HT_ShowOnlyTopBuildings = [];
  2866. this.HT_ShowOnlyAffordableBuildings = [];
  2867. this.HT_CityBuildings = [];
  2868. for (var mPage in this.HT_Pages) {
  2869. this.createOptions(mPage);
  2870. this.HT_Pages[mPage].add(this.HT_Options[mPage]);
  2871. this.HT_Pages[mPage].add(this.HT_Tables[mPage], {
  2872. flex: 1
  2873. });
  2874. this.HT_TabView.add(this.HT_Pages[mPage]);
  2875. }
  2876.  
  2877. // Zeigen wir Dollars an !
  2878. this.HT_TabView.setSelection([this.HT_TabView.getChildren()[2]]);
  2879. this.HT_SelectedResourceType = ClientLib.Base.EResourceType.Gold;
  2880.  
  2881. // Nöööööö, ich will Tiberium ! ;P
  2882. this.HT_TabView.setSelection([this.HT_TabView.getChildren()[0]]);
  2883. this.HT_SelectedResourceType = ClientLib.Base.EResourceType.Tiberium;
  2884. } catch (e) {
  2885. console.log("HuffyTools.UpgradePriority.init: ", e);
  2886. }
  2887. },
  2888. createOptions: function (eType) {
  2889. var oBox = new qx.ui.layout.Flow();
  2890. var oOptions = new qx.ui.container.Composite(oBox);
  2891. oOptions.setMargin(5);
  2892. this.HT_ShowOnlyTopBuildings[eType] = new qx.ui.form.CheckBox(Lang.gt("display only top buildings"));
  2893. this.HT_ShowOnlyTopBuildings[eType].setMargin(5);
  2894. this.HT_ShowOnlyTopBuildings[eType].setValue(MaelstromTools.LocalStorage.get("UGL_TOPBUILDINGS_" + eType, true));
  2895. this.HT_ShowOnlyTopBuildings[eType].addListener("execute", this.CBChanged, this);
  2896. oOptions.add(this.HT_ShowOnlyTopBuildings[eType], {
  2897. left: 10,
  2898. top: 10
  2899. });
  2900. this.HT_ShowOnlyAffordableBuildings[eType] = new qx.ui.form.CheckBox(Lang.gt("display only affordable buildings"));
  2901. this.HT_ShowOnlyAffordableBuildings[eType].setMargin(5);
  2902. this.HT_ShowOnlyAffordableBuildings[eType].setValue(MaelstromTools.LocalStorage.get("UGL_AFFORDABLE_" + eType, true));
  2903. this.HT_ShowOnlyAffordableBuildings[eType].addListener("execute", this.CBChanged, this);
  2904. oOptions.add(this.HT_ShowOnlyAffordableBuildings[eType], {
  2905. left: 10,
  2906. top: 10,
  2907. lineBreak: true
  2908. });
  2909. this.HT_CityBuildings[eType] = [];
  2910. for (var cname in MT_Cache.Cities) {
  2911. var oCity = MT_Cache.Cities[cname].Object;
  2912. var oCityBuildings = new HuffyTools.CityCheckBox(cname);
  2913. oCityBuildings.HT_CityID = oCity.get_Id();
  2914. oCityBuildings.setMargin(5);
  2915. oCityBuildings.setValue(MaelstromTools.LocalStorage.get("UGL_CITYFILTER_" + eType + "_" + oCity.get_Id(), true));
  2916. oCityBuildings.addListener("execute", this.CBChanged, this);
  2917. oOptions.add(oCityBuildings, {
  2918. left: 10,
  2919. top: 10
  2920. });
  2921. this.HT_CityBuildings[eType][cname] = oCityBuildings;
  2922. }
  2923. var buttonUpgradeAll = new qx.ui.form.Button("UpgradeAll").set({
  2924. width : 80,
  2925. appearance : "button-text-small",
  2926. toolTipText : "Upgrade all filtered buildings"
  2927. });
  2928. buttonUpgradeAll.addListener("execute", function (e) {
  2929. this.upgradeAll(e, eType);
  2930. }, this);
  2931. oOptions.add(buttonUpgradeAll, {
  2932. left: 10,
  2933. top: 10
  2934. });
  2935. this.HT_Options[eType] = oOptions;
  2936. },
  2937. createTable: function (eType) {
  2938. try {
  2939. this.HT_Models[eType] = new qx.ui.table.model.Simple();
  2940. this.HT_Models[eType].setColumns(["ID", Lang.gt("City"), Lang.gt("Type (coord)"), Lang.gt("to Level"), Lang.gt("Gain/h"), Lang.gt("Factor"), Lang.gt("Tiberium"), Lang.gt("Power"), Lang.gt("Tib/gain"), "ROI Tib. [d]", Lang.gt("Pow/gain"), "ROI Power [d]", Lang.gt("ETA"), Lang.gt("Upgrade"), "State"]);
  2941. this.HT_Tables[eType] = new qx.ui.table.Table(this.HT_Models[eType]);
  2942. this.HT_Tables[eType].setColumnVisibilityButtonVisible(false);
  2943. this.HT_Tables[eType].setColumnWidth(0, 0);
  2944. this.HT_Tables[eType].setColumnWidth(1, 90);
  2945. this.HT_Tables[eType].setColumnWidth(2, 120);
  2946. this.HT_Tables[eType].setColumnWidth(3, 70);
  2947. this.HT_Tables[eType].setColumnWidth(4, 120);
  2948. this.HT_Tables[eType].setColumnWidth(5, 60);
  2949. this.HT_Tables[eType].setColumnWidth(6, 70);
  2950. this.HT_Tables[eType].setColumnWidth(7, 70);
  2951. this.HT_Tables[eType].setColumnWidth(8, 100);
  2952. this.HT_Tables[eType].setColumnWidth(9, 90);
  2953. this.HT_Tables[eType].setColumnWidth(10, 100);
  2954. this.HT_Tables[eType].setColumnWidth(11, 90);
  2955. this.HT_Tables[eType].setColumnWidth(12, 80);
  2956. this.HT_Tables[eType].setColumnWidth(13, 45);
  2957. this.HT_Tables[eType].setColumnWidth(14, 0);
  2958. var tcm = this.HT_Tables[eType].getTableColumnModel();
  2959. tcm.setColumnVisible(0, false);
  2960. tcm.setColumnVisible(10, false);//power/zuwachs
  2961. tcm.setColumnVisible(11, false);//power roi
  2962. tcm.setColumnVisible(14, false);
  2963. tcm.setDataCellRenderer(4, new qx.ui.table.cellrenderer.Number().set({
  2964. numberFormat: new qx.util.format.NumberFormat().set({
  2965. maximumFractionDigits: 2,
  2966. minimumFractionDigits: 2
  2967. })
  2968. }));
  2969. tcm.setDataCellRenderer(5, new qx.ui.table.cellrenderer.Number().set({
  2970. numberFormat: new qx.util.format.NumberFormat().set({
  2971. maximumFractionDigits: 5,
  2972. minimumFractionDigits: 5
  2973. })
  2974. }));
  2975. tcm.setDataCellRenderer(6, new HuffyTools.ReplaceRender().set({
  2976. ReplaceFunction: this.formatTiberiumAndPower
  2977. }));
  2978. tcm.setDataCellRenderer(7, new HuffyTools.ReplaceRender().set({
  2979. ReplaceFunction: this.formatTiberiumAndPower
  2980. }));
  2981. tcm.setDataCellRenderer(13, new HuffyTools.ImageRender(40, 20));
  2982. } catch (e) {
  2983. console.log("HuffyTools.UpgradePriority.createTable: ", e);
  2984. }
  2985. },
  2986. createTabPage: function (resource_type) {
  2987. try {
  2988. var sName = MaelstromTools.Statics.LootTypeName(resource_type);
  2989. var oRes = new qx.ui.tabview.Page(Lang.gt(sName), MT_Base.images[sName]);
  2990. oRes.setLayout(new qx.ui.layout.VBox(2));
  2991. oRes.setPadding(5);
  2992. var btnTab = oRes.getChildControl("button");
  2993. btnTab.resetWidth();
  2994. btnTab.resetHeight();
  2995. btnTab.set({
  2996. show: "icon",
  2997. margin: 0,
  2998. padding: 0,
  2999. toolTipText: sName
  3000. });
  3001. btnTab.addListener("execute", this.TabChanged, [this, resource_type]);
  3002. this.HT_Pages[resource_type] = oRes;
  3003. return oRes;
  3004. } catch (e) {
  3005. console.log("HuffyTools.UpgradePriority.createTabPage: ", e);
  3006. }
  3007. },
  3008.  
  3009. TabChanged: function (e) { //TABELLENSPALTEN ANZEIGEN/AUSBLENDEN
  3010. try {
  3011. this[0].HT_SelectedResourceType = this[1];
  3012. this[0].UpgradeCompleted(null, null);
  3013. console.log("TABCHANGE: ");
  3014. console.log(this);
  3015. console.log(this[1]);
  3016. console.log("tib: " + ClientLib.Base.EResourceType.Tiberium);
  3017. console.log("pow: " + ClientLib.Base.EResourceType.Power);
  3018. var tcm = this[0].HT_Tables[this[1]].getTableColumnModel();
  3019. if(this[1] == ClientLib.Base.EResourceType.Tiberium){
  3020. tcm.setColumnVisible(8, true);
  3021. tcm.setColumnVisible(9, true);
  3022. }
  3023. else{
  3024. tcm.setColumnVisible(8, false);
  3025. tcm.setColumnVisible(9, false);
  3026. }
  3027. if(this[1] == ClientLib.Base.EResourceType.Power){
  3028. tcm.setColumnVisible(10, true);
  3029. tcm.setColumnVisible(11, true);
  3030. }
  3031. else{
  3032. tcm.setColumnVisible(10, false);
  3033. tcm.setColumnVisible(11, false);
  3034. }
  3035. } catch (e) {
  3036. console.log("HuffyTools.UpgradePriority.TabChanged: ", e);
  3037. }
  3038. },
  3039. upgradeAll: function (e, eResourceType) {
  3040. try {
  3041. if (this.upgradeToDo == null) {
  3042. this.upgradeToDoType = parseInt(eResourceType);
  3043. this.upgradeToDo = this.HT_Models[eResourceType].getData();
  3044. }
  3045. if (this.upgradeToDo.length > 0) {
  3046. this.upgradeInProgress = true;
  3047. var current = this.upgradeToDo.pop();
  3048. var buildingID = current[0];
  3049. var iState = parseInt(current[12]);
  3050. if (iState != 1) {
  3051. return;
  3052. }
  3053. if (buildingID in this.BuildingList) {
  3054. if (PerforceChangelist >= 382917) { //new
  3055. ClientLib.Net.CommunicationManager.GetInstance().SendCommand("UpgradeBuilding", this.BuildingList[buildingID], phe.cnc.Util.createEventDelegate(ClientLib.Net.CommandResult, this, this.upgradeAllCompleted), null, true);
  3056. } else { //old
  3057. ClientLib.Net.CommunicationManager.GetInstance().SendCommand("UpgradeBuilding", this.BuildingList[buildingID], webfrontend.Util.createEventDelegate(ClientLib.Net.CommandResult, this, this.upgradeAllCompleted), null, true);
  3058. }
  3059. }
  3060. } else {
  3061. this.upgradeToDo = null;
  3062. }
  3063. } catch (e) {
  3064. console.log("HuffyTools.UpgradePriority.upgradeBuilding: ", e);
  3065. }
  3066. },
  3067. upgradeAllCompleted: function (context, result) {
  3068. var self = this;
  3069. if (this.upgradeToDo.length > 0) {
  3070. setTimeout(function () {
  3071. self.upgradeAll(self.upgradeToDoType);
  3072. }, 100);
  3073. } else {
  3074. this.upgradeToDoType = null;
  3075. this.upgradeToDo = null;
  3076. setTimeout(function () {
  3077. self.calc();
  3078. }, 100);
  3079. this.upgradeInProgress = false;
  3080. }
  3081. },
  3082. upgradeBuilding: function (e, eResourceType) {
  3083. if (this.upgradeInProgress == true) {
  3084. console.log("upgradeBuilding:", "upgrade in progress !");
  3085. return;
  3086. }
  3087. try {
  3088. if (e.getColumn() == 11) {
  3089. var buildingID = this.HT_Models[eResourceType].getValue(0, e.getRow());
  3090. var iState = parseInt(this.HT_Models[eResourceType].getValue(12, e.getRow()));
  3091. if (iState != 1) {
  3092. return;
  3093. }
  3094. if (buildingID in this.BuildingList) {
  3095. this.upgradeInProgress = true;
  3096. if (PerforceChangelist >= 382917) { //new
  3097. ClientLib.Net.CommunicationManager.GetInstance().SendCommand("UpgradeBuilding", this.BuildingList[buildingID], phe.cnc.Util.createEventDelegate(ClientLib.Net.CommandResult, this, this.UpgradeCompleted), null, true);
  3098. } else { //old
  3099. ClientLib.Net.CommunicationManager.GetInstance().SendCommand("UpgradeBuilding", this.BuildingList[buildingID], webfrontend.Util.createEventDelegate(ClientLib.Net.CommandResult, this, this.UpgradeCompleted), null, true);
  3100. }
  3101. }
  3102. }
  3103. } catch (e) {
  3104. console.log("HuffyTools.UpgradePriority.upgradeBuilding: ", e);
  3105. }
  3106. },
  3107. UpgradeCompleted: function (context, result) {
  3108. /* Dodgy solution to get upgrade priority working.
  3109. Upgrades in the game were reworked in the February patch and again in the March patch.
  3110. In the past resources were deducted from the base immediately when the upgrade command was sent, but now it is done moments after the upgrade has been completed.
  3111. When running updateCache() immediately after the upgrade it will still return with the pre-upgrade resource amounts.
  3112. A one second delay will work as a temporary solution giving the base enough time to update to reflect the new resource amounts.
  3113. A better solution could be to monitor for the reduction in resources after an upgrade and once it takes place only then update the cache.
  3114. */
  3115. var self = this;
  3116. setTimeout(function () {
  3117. self.calc();
  3118. }, 1000);
  3119. //this.calc();
  3120. this.upgradeInProgress = false;
  3121. },
  3122. CBChanged: function (e) {
  3123. this.UpgradeCompleted(null, null);
  3124. },
  3125. formatTiberiumAndPower: function (oValue) {
  3126. if (PerforceChangelist >= 387751) { //new
  3127. return phe.cnc.gui.util.Numbers.formatNumbersCompact(oValue);
  3128. } else { //old
  3129. return webfrontend.gui.Util.formatNumbersCompact(oValue);
  3130. }
  3131. },
  3132. updateCache: function () {
  3133. try {
  3134. if (!this.HT_TabView) {
  3135. this.init();
  3136. }
  3137. var eType = this.HT_SelectedResourceType;
  3138. var bTop = this.HT_ShowOnlyTopBuildings[eType].getValue();
  3139. MaelstromTools.LocalStorage.set("UGL_TOPBUILDINGS_" + eType, bTop);
  3140. var bAffordable = this.HT_ShowOnlyAffordableBuildings[eType].getValue();
  3141. MaelstromTools.LocalStorage.set("UGL_AFFORDABLE_" + eType, bAffordable);
  3142. var oCityFilter = [];
  3143. for (var cname in this.HT_CityBuildings[eType]) {
  3144. var oCityBuildings = this.HT_CityBuildings[eType][cname];
  3145. var bFilterBuilding = oCityBuildings.getValue();
  3146. MaelstromTools.LocalStorage.set("UGL_CITYFILTER_" + eType + "_" + oCityBuildings.HT_CityID, bFilterBuilding);
  3147. oCityFilter[cname] = bFilterBuilding;
  3148. }
  3149. HuffyTools.UpgradePriority.getInstance().collectData(bTop, bAffordable, oCityFilter, eType);
  3150. } catch (e) {
  3151. console.log("HuffyTools.UpgradePriority.updateCache: ", e);
  3152. }
  3153. },
  3154. setWidgetLabels: function () { //HIIIIIER BERECHNUNG FÜR ROI ??????????????????????
  3155. try {
  3156. var HuffyCalc = HuffyTools.UpgradePriority.getInstance();
  3157. var UpgradeList = HuffyCalc.Cache;
  3158.  
  3159. for (var eResourceType in UpgradeList) {
  3160. //var eResourceType = MaelstromTools.Statics.LootTypeName(eResourceName);
  3161. var rowData = [];
  3162.  
  3163. this.HT_Models[eResourceType].setData([]);
  3164.  
  3165. for (var mCity in UpgradeList[eResourceType]) {
  3166. for (var mBuilding in UpgradeList[eResourceType][mCity]) {
  3167. var UpItem = UpgradeList[eResourceType][mCity][mBuilding];
  3168. if (typeof (UpItem.Type) == "undefined") {
  3169. continue;
  3170. }
  3171. if (!(mBuilding in this.BuildingList)) {
  3172. this.BuildingList[UpItem.ID] = UpItem.Building;
  3173. }
  3174. var iTiberiumCosts = 0;
  3175. if (ClientLib.Base.EResourceType.Tiberium in UpItem.Costs) {
  3176. iTiberiumCosts = UpItem.Costs[ClientLib.Base.EResourceType.Tiberium];
  3177. }
  3178. var iTiberiumPerGain = 0;
  3179. var roiTib = 0;
  3180. if (ClientLib.Base.EResourceType.Tiberium in UpItem.Costs) {
  3181. iTiberiumPerGain = UpItem.Costs[ClientLib.Base.EResourceType.Tiberium] / UpItem.GainPerHour;
  3182. roiTib = (iTiberiumPerGain / 24);
  3183. }
  3184. var iPowerCosts = 0;
  3185. if (ClientLib.Base.EResourceType.Power in UpItem.Costs) {
  3186. iPowerCosts = UpItem.Costs[ClientLib.Base.EResourceType.Power];
  3187. }
  3188. var iPowerPerGain = 0;
  3189. var roiPow = 0;
  3190. if (ClientLib.Base.EResourceType.Power in UpItem.Costs) {
  3191. iPowerPerGain = UpItem.Costs[ClientLib.Base.EResourceType.Power] / UpItem.GainPerHour;
  3192. roiPow = (iPowerPerGain / 24);
  3193. }
  3194. var img = MT_Base.images["UpgradeBuilding"];
  3195. if (UpItem.Affordable == false) {
  3196. img = "";
  3197. }
  3198. var sType = UpItem.Type;
  3199. sType = sType + "(" + UpItem.PosX + ":" + UpItem.PosY + ")";
  3200. var iETA = 0;
  3201. if (UpItem.TimeTillUpgradable[ClientLib.Base.EResourceType.Tiberium] > 0) {
  3202. iETA = UpItem.TimeTillUpgradable[ClientLib.Base.EResourceType.Tiberium];
  3203. }
  3204. if (UpItem.TimeTillUpgradable[ClientLib.Base.EResourceType.Power] > iETA) {
  3205. iETA = UpItem.TimeTillUpgradable[ClientLib.Base.EResourceType.Power];
  3206. }
  3207. var sETA = "";
  3208. if (iETA > 0) {
  3209. sETA = ClientLib.Vis.VisMain.FormatTimespan(iETA);
  3210. }
  3211. var iState = 0;
  3212. if (UpItem.Affordable == true) {
  3213. iState = 1;
  3214. } else if (UpItem.AffordableByTransfer == true) {
  3215. iState = 2;
  3216. } else {
  3217. iState = 3;
  3218. }
  3219. rowData.push([UpItem.ID, mCity, sType, UpItem.Level, UpItem.GainPerHour, UpItem.Ticks, iTiberiumCosts, iPowerCosts, iTiberiumPerGain, roiTib, iPowerPerGain, roiPow, sETA, img, iState]);
  3220. }
  3221. }
  3222. this.HT_Models[eResourceType].setData(rowData);
  3223. }
  3224. } catch (e) {
  3225. console.log("HuffyTools.UpgradePriority.setWidgetLabels: ", e);
  3226. }
  3227. }
  3228. }
  3229. });
  3230.  
  3231. // define HuffyTools.UpgradePriority
  3232. qx.Class.define("HuffyTools.UpgradePriority", {
  3233. type: "singleton",
  3234. extend: qx.core.Object,
  3235. members: {
  3236. list_units: null,
  3237. list_buildings: null,
  3238.  
  3239. comparePrio: function (elem1, elem2) {
  3240. if (elem1.Ticks < elem2.Ticks) return -1;
  3241. if (elem1.Ticks > elem2.Ticks) return 1;
  3242. return 0;
  3243. },
  3244. getPrioList: function (city, arTechtypes, eModPackageSize, eModProduction, bOnlyTopBuildings, bOnlyAffordableBuildings) {
  3245. try {
  3246. var RSI = MaelstromTools.ResourceOverview.getInstance();
  3247. RSI.updateCache();
  3248. var TotalTiberium = 0;
  3249.  
  3250. for (var cityName in this.Cache) {
  3251. var cityCache = this.Cache[cityName];
  3252. var i = cityCache[MaelstromTools.Statics.Tiberium];
  3253. if (typeof (i) !== 'undefined') {
  3254. TotalTiberium += i;
  3255. //but never goes here during test.... // to optimize - to do
  3256. }
  3257. }
  3258. var resAll = [];
  3259. var prod = MaelstromTools.Production.getInstance().updateCache(city.get_Name());
  3260. //var buildings = MaelstromTools.Wrapper.GetBuildings(city.get_CityBuildingsData());
  3261. var buildings = city.get_Buildings().d;
  3262.  
  3263. // 376877 & old fixes
  3264. var objbuildings = [];
  3265. if (PerforceChangelist >= 376877) { //new
  3266. for (var o in buildings) objbuildings.push(buildings[o]);
  3267. } else { //old
  3268. for (var i = 0; i < buildings.length; i++) objbuildings.push(buildings[i]);
  3269. }
  3270.  
  3271.  
  3272. for (var i = 0; i < objbuildings.length; i++) {
  3273. var city_building = objbuildings[i];
  3274.  
  3275. // TODO: check for destroyed building
  3276.  
  3277. var iTechType = city_building.get_TechName();
  3278. var bSkip = true;
  3279. for (var iTypeKey in arTechtypes) {
  3280. if (arTechtypes[iTypeKey] == iTechType) {
  3281. bSkip = false;
  3282. break;
  3283. }
  3284. }
  3285. if (bSkip == true) {
  3286. continue;
  3287. }
  3288. var city_buildingdetailview = city.GetBuildingDetailViewInfo(city_building);
  3289. if (city_buildingdetailview == null) {
  3290. continue;
  3291. }
  3292. var bindex = city_building.get_Id();
  3293. var resbuilding = [];
  3294. resbuilding["ID"] = bindex;
  3295. resbuilding["Type"] = this.TechTypeName(parseInt(iTechType, 10));
  3296. resbuilding["PosX"] = city_building.get_CoordX();
  3297. resbuilding["PosY"] = city_building.get_CoordY();
  3298.  
  3299. resbuilding["Building"] = {
  3300. cityid: city.get_Id(),
  3301. posX: resbuilding["PosX"],
  3302. posY: resbuilding["PosY"],
  3303. isPaid: true
  3304. };
  3305.  
  3306. resbuilding["GainPerHour"] = 0;
  3307. resbuilding["Level"] = city_building.get_CurrentLevel() + 1;
  3308. for (var ModifierType in city_buildingdetailview.OwnProdModifiers.d) {
  3309. switch (parseInt(ModifierType, 10)) {
  3310. case eModPackageSize:
  3311. {
  3312. var ModOj = city_buildingdetailview.OwnProdModifiers.d[city_building.get_MainModifierTypeId()];
  3313. var Mod = (ModOj.TotalValue + ModOj.NewLvlDelta) / ClientLib.Data.MainData.GetInstance().get_Time().get_StepsPerHour();
  3314. resbuilding["GainPerHour"] += (city_buildingdetailview.OwnProdModifiers.d[ModifierType].NewLvlDelta / Mod);
  3315. break;
  3316. }
  3317. case eModProduction:
  3318. {
  3319. resbuilding["GainPerHour"] += city_buildingdetailview.OwnProdModifiers.d[ModifierType].NewLvlDelta;
  3320. break;
  3321. }
  3322. }
  3323. }
  3324. // Nutzen ins Verhältnis zu den Kosten setzten
  3325. var TechLevelData = ClientLib.Base.Util.GetTechLevelResourceRequirements_Obj(city_building.get_CurrentLevel() + 1, city_building.get_TechGameData_Obj());
  3326. var RatioPerCostType = {};
  3327. var sRatio = "";
  3328. var sCosts = "";
  3329. var lTicks = 0;
  3330. var bHasPower = true;
  3331. var bHasTiberium = true;
  3332. var bAffordableByTransfer = true;
  3333. var oCosts = [];
  3334. var oTimes = [];
  3335. for (var costtype in TechLevelData) {
  3336. if (typeof (TechLevelData[costtype]) == "function") {
  3337. continue;
  3338. }
  3339. if (TechLevelData[costtype].Type == "0") {
  3340. continue;
  3341. }
  3342.  
  3343. oCosts[TechLevelData[costtype].Type] = TechLevelData[costtype].Count;
  3344. if (parseInt(TechLevelData[costtype].Count) <= 0) {
  3345. continue;
  3346. }
  3347. RatioPerCostType[costtype] = TechLevelData[costtype].Count / resbuilding["GainPerHour"];
  3348. if (sCosts.length > 0) {
  3349. sCosts = sCosts + ", ";
  3350. }
  3351. sCosts = sCosts + MaelstromTools.Wrapper.FormatNumbersCompact(TechLevelData[costtype].Count) + " " + MaelstromTools.Statics.LootTypeName(TechLevelData[costtype].Type);
  3352. if (sRatio.length > 0) {
  3353. sRatio = sRatio + ", ";
  3354. }
  3355. // Upgrade affordable ?
  3356. if (city.GetResourceCount(TechLevelData[costtype].Type) < TechLevelData[costtype].Count) {
  3357. switch (TechLevelData[costtype].Type) {
  3358. case ClientLib.Base.EResourceType.Tiberium:
  3359. {
  3360. bHasTiberium = false;
  3361. if (TotalTiberium < TechLevelData[costtype].Count) {
  3362. bAffordableByTransfer = false;
  3363. }
  3364. }
  3365. break;
  3366. case ClientLib.Base.EResourceType.Power:
  3367. {
  3368. bHasPower = false;
  3369. }
  3370. break;
  3371. }
  3372. }
  3373. sRatio = sRatio + MaelstromTools.Wrapper.FormatNumbersCompact(RatioPerCostType[costtype]);
  3374.  
  3375. var techlevelData = MaelstromTools.Statics.LootTypeName(TechLevelData[costtype].Type);
  3376.  
  3377. var dCityProduction = prod[techlevelData].Delta + prod[techlevelData].ExtraBonusDelta + prod[techlevelData].POI;
  3378. if (dCityProduction > 0) {
  3379. if (lTicks < (3600 * RatioPerCostType[costtype] / dCityProduction)) {
  3380. lTicks = (3600 * RatioPerCostType[costtype] / dCityProduction);
  3381. }
  3382. }
  3383. oTimes[TechLevelData[costtype].Type] = 0;
  3384. if (oCosts[TechLevelData[costtype].Type] > city.GetResourceCount(TechLevelData[costtype].Type)) {
  3385. oTimes[TechLevelData[costtype].Type] = (3600 * (oCosts[TechLevelData[costtype].Type] - city.GetResourceCount(TechLevelData[costtype].Type))) / dCityProduction;
  3386. }
  3387. }
  3388. resbuilding["Ticks"] = lTicks;
  3389. resbuilding["Time"] = ClientLib.Vis.VisMain.FormatTimespan(lTicks);
  3390. resbuilding["Costtext"] = sCosts;
  3391. resbuilding["Costs"] = oCosts;
  3392. resbuilding["TimeTillUpgradable"] = oTimes;
  3393. resbuilding["Ratio"] = sRatio;
  3394. resbuilding["Affordable"] = bHasTiberium && bHasPower;
  3395. resbuilding["AffordableByTransfer"] = bHasPower && bAffordableByTransfer;
  3396. if (resbuilding["GainPerHour"] > 0 && (bOnlyAffordableBuildings == false || resbuilding["Affordable"] == true)) {
  3397. resAll[bindex] = resbuilding;
  3398. }
  3399. }
  3400.  
  3401.  
  3402. resAll = resAll.sort(this.comparePrio);
  3403. if (!bOnlyTopBuildings) {
  3404. return resAll;
  3405. }
  3406. var res2 = [];
  3407. if (MaelstromTools.Util.ArraySize(resAll) > 0) {
  3408. var iTopNotAffordable = -1;
  3409. var iTopAffordable = -1;
  3410. var iNextNotAffordable = -1;
  3411. var iLastIndex = -1;
  3412. for (var iNewIndex in resAll) {
  3413. if (resAll[iNewIndex].Affordable == true) {
  3414. if (iTopAffordable == -1) {
  3415. iTopAffordable = iNewIndex;
  3416. iNextNotAffordable = iLastIndex;
  3417. }
  3418. } else {
  3419. if (iTopNotAffordable == -1) {
  3420. iTopNotAffordable = iNewIndex;
  3421. }
  3422. }
  3423. iLastIndex = iNewIndex;
  3424. }
  3425. if (iTopAffordable == -1) {
  3426. iNextNotAffordable = iLastIndex;
  3427. }
  3428. var iIndex = 0;
  3429. if (iTopNotAffordable != -1) {
  3430. res2[iIndex++] = resAll[iTopNotAffordable];
  3431. }
  3432. if (iNextNotAffordable != -1) {
  3433. res2[iIndex++] = resAll[iNextNotAffordable];
  3434. }
  3435. if (iTopAffordable != -1) {
  3436. res2[iIndex++] = resAll[iTopAffordable];
  3437. }
  3438. }
  3439. res2 = res2.sort(this.comparePrio);
  3440. return res2;
  3441. } catch (e) {
  3442. console.log("HuffyTools.getPrioList: ", e);
  3443. }
  3444. },
  3445. TechTypeName: function (iTechType) {
  3446. switch (iTechType) {
  3447. case ClientLib.Base.ETechName.PowerPlant:
  3448. {
  3449. return Lang.gt("Powerplant");
  3450. break;
  3451. }
  3452. case ClientLib.Base.ETechName.Refinery:
  3453. {
  3454. return Lang.gt("Refinery");
  3455. break;
  3456. }
  3457. case ClientLib.Base.ETechName.Harvester_Crystal:
  3458. {
  3459. return Lang.gt("Harvester");
  3460. break;
  3461. }
  3462. case ClientLib.Base.ETechName.Harvester:
  3463. {
  3464. return Lang.gt("Harvester");
  3465. break;
  3466. }
  3467. case ClientLib.Base.ETechName.Silo:
  3468. {
  3469. return Lang.gt("Silo");
  3470. break;
  3471. }
  3472. case ClientLib.Base.ETechName.Accumulator:
  3473. {
  3474. return Lang.gt("Accumulator");
  3475. break;
  3476. }
  3477. }
  3478. return "?";
  3479. },
  3480. collectData: function (bOnlyTopBuildings, bOnlyAffordableBuildings, oCityFilter, eSelectedResourceType) {
  3481. try {
  3482. MT_Cache.updateCityCache();
  3483. this.Cache = {};
  3484. if (eSelectedResourceType == ClientLib.Base.EResourceType.Tiberium) {
  3485. this.Cache[ClientLib.Base.EResourceType.Tiberium] = {};
  3486. }
  3487. if (eSelectedResourceType == ClientLib.Base.EResourceType.Crystal) {
  3488. this.Cache[ClientLib.Base.EResourceType.Crystal] = {};
  3489. }
  3490. if (eSelectedResourceType == ClientLib.Base.EResourceType.Power) {
  3491. this.Cache[ClientLib.Base.EResourceType.Power] = {};
  3492. }
  3493. if (eSelectedResourceType == ClientLib.Base.EResourceType.Gold) {
  3494. this.Cache[ClientLib.Base.EResourceType.Gold] = {};
  3495. }
  3496. for (var cname in MT_Cache.Cities) {
  3497. var city = MT_Cache.Cities[cname].Object;
  3498. if (oCityFilter[cname] == false) {
  3499. continue;
  3500. }
  3501. if (eSelectedResourceType == ClientLib.Base.EResourceType.Tiberium) {
  3502. this.Cache[ClientLib.Base.EResourceType.Tiberium][cname] = this.getPrioList(city, [ClientLib.Base.ETechName.Harvester, ClientLib.Base.ETechName.Silo], ClientLib.Base.EModifierType.TiberiumPackageSize, ClientLib.Base.EModifierType.TiberiumProduction, bOnlyTopBuildings, bOnlyAffordableBuildings);
  3503. }
  3504. if (eSelectedResourceType == ClientLib.Base.EResourceType.Crystal) {
  3505. this.Cache[ClientLib.Base.EResourceType.Crystal][cname] = this.getPrioList(city, [ClientLib.Base.ETechName.Harvester, ClientLib.Base.ETechName.Silo], ClientLib.Base.EModifierType.CrystalPackageSize, ClientLib.Base.EModifierType.CrystalProduction, bOnlyTopBuildings, bOnlyAffordableBuildings);
  3506. }
  3507. if (eSelectedResourceType == ClientLib.Base.EResourceType.Power) {
  3508. this.Cache[ClientLib.Base.EResourceType.Power][cname] = this.getPrioList(city, [ClientLib.Base.ETechName.PowerPlant, ClientLib.Base.ETechName.Accumulator], ClientLib.Base.EModifierType.PowerPackageSize, ClientLib.Base.EModifierType.PowerProduction, bOnlyTopBuildings, bOnlyAffordableBuildings);
  3509. }
  3510. if (eSelectedResourceType == ClientLib.Base.EResourceType.Gold) {
  3511. this.Cache[ClientLib.Base.EResourceType.Gold][cname] = this.getPrioList(city, [ClientLib.Base.ETechName.Refinery, ClientLib.Base.ETechName.PowerPlant], ClientLib.Base.EModifierType.CreditsPackageSize, ClientLib.Base.EModifierType.CreditsProduction, bOnlyTopBuildings, bOnlyAffordableBuildings);
  3512. }
  3513. }
  3514. } catch (e) {
  3515. console.log("HuffyTools.UpgradePriority.collectData: ", e);
  3516. }
  3517. }
  3518. }
  3519. });
  3520.  
  3521. var __MTCity_initialized = false; //k undeclared
  3522.  
  3523. var Lang = MaelstromTools.Language.getInstance();
  3524. var MT_Cache = MaelstromTools.Cache.getInstance();
  3525. var MT_Base = MaelstromTools.Base.getInstance();
  3526. var MT_Preferences = MaelstromTools.Preferences.getInstance();
  3527. MT_Preferences.readOptions();
  3528.  
  3529. if (!webfrontend.gui.region.RegionCityMenu.prototype.__MTCity_showMenu) {
  3530. webfrontend.gui.region.RegionCityMenu.prototype.__MTCity_showMenu = webfrontend.gui.region.RegionCityMenu.prototype.showMenu;
  3531. }
  3532. webfrontend.gui.region.RegionCityMenu.prototype.showMenu = function (selectedVisObject) {
  3533.  
  3534. MT_Cache.SelectedBaseForMenu = selectedVisObject;
  3535. var baseStatusOverview = MaelstromTools.BaseStatus.getInstance();
  3536.  
  3537. if (__MTCity_initialized == false) {
  3538. //console.log(selectedBase.get_Name());
  3539. __MTCity_initialized = true;
  3540. baseStatusOverview.CityMenuButtons = [];
  3541.  
  3542. for (var k in this) {
  3543. try {
  3544. if (this.hasOwnProperty(k)) {
  3545. if (this[k] && this[k].basename == "Composite") {
  3546. var button = new qx.ui.form.Button(Lang.gt("Calibrate support"));
  3547. button.addListener("execute", function (e) {
  3548. MaelstromTools.Util.calibrateWholeSupportOnSelectedBase();
  3549. }, this);
  3550.  
  3551. this[k].add(button);
  3552. baseStatusOverview.CityMenuButtons.push(button);
  3553. }
  3554. }
  3555. } catch (e) {
  3556. console.log("webfrontend.gui.region.RegionCityMenu.prototype.showMenu: ", e);
  3557. }
  3558. }
  3559. }
  3560.  
  3561. var isAllowed = MaelstromTools.Util.checkIfSupportIsAllowed(MT_Cache.SelectedBaseForMenu);
  3562.  
  3563. for (var x = 0; x < baseStatusOverview.CityMenuButtons.length; ++x) {
  3564. baseStatusOverview.CityMenuButtons[x].setVisibility(isAllowed ? 'visible' : 'excluded');
  3565. }
  3566. this.__MTCity_showMenu(selectedVisObject);
  3567. };
  3568.  
  3569. if (MT_Preferences.Settings.showLoot) {
  3570. // Wrap onCitiesChange method
  3571. if (!webfrontend.gui.region.RegionNPCCampStatusInfo.prototype.__MTCity_NPCCamp) {
  3572. webfrontend.gui.region.RegionNPCCampStatusInfo.prototype.__MTCity_NPCCamp = webfrontend.gui.region.RegionNPCCampStatusInfo.prototype.onCitiesChange;
  3573. }
  3574. webfrontend.gui.region.RegionNPCCampStatusInfo.prototype.onCitiesChange = function () {
  3575. MT_Base.updateLoot(1, ClientLib.Vis.VisMain.GetInstance().get_SelectedObject(), webfrontend.gui.region.RegionNPCCampStatusInfo.getInstance());
  3576. return this.__MTCity_NPCCamp();
  3577. };
  3578.  
  3579. if (!webfrontend.gui.region.RegionNPCBaseStatusInfo.prototype.__MTCity_NPCBase) {
  3580. webfrontend.gui.region.RegionNPCBaseStatusInfo.prototype.__MTCity_NPCBase = webfrontend.gui.region.RegionNPCBaseStatusInfo.prototype.onCitiesChange;
  3581. }
  3582. webfrontend.gui.region.RegionNPCBaseStatusInfo.prototype.onCitiesChange = function () {
  3583. MT_Base.updateLoot(2, ClientLib.Vis.VisMain.GetInstance().get_SelectedObject(), webfrontend.gui.region.RegionNPCBaseStatusInfo.getInstance());
  3584. //MT_Base.updateLoot(2, ClientLib.Data.MainData.GetInstance().get_Cities().get_CurrentCity(), webfrontend.gui.region.RegionNPCBaseStatusInfo.getInstance());
  3585. return this.__MTCity_NPCBase();
  3586. };
  3587.  
  3588. if (!webfrontend.gui.region.RegionCityStatusInfoEnemy.prototype.__MTCity_City) {
  3589. webfrontend.gui.region.RegionCityStatusInfoEnemy.prototype.__MTCity_City = webfrontend.gui.region.RegionCityStatusInfoEnemy.prototype.onCitiesChange;
  3590. }
  3591. webfrontend.gui.region.RegionCityStatusInfoEnemy.prototype.onCitiesChange = function () {
  3592. MT_Base.updateLoot(3, ClientLib.Vis.VisMain.GetInstance().get_SelectedObject(), webfrontend.gui.region.RegionCityStatusInfoEnemy.getInstance());
  3593. //MT_Base.updateLoot(3, ClientLib.Data.MainData.GetInstance().get_Cities().get_CurrentCity(), webfrontend.gui.region.RegionCityStatusInfoEnemy.getInstance());
  3594. return this.__MTCity_City();
  3595. };
  3596. }
  3597.  
  3598. }
  3599. } catch (e) {
  3600. console.log("createMaelstromTools: ", e);
  3601. }
  3602.  
  3603. function MaelstromTools_checkIfLoaded() {
  3604. try {
  3605. if (typeof qx != 'undefined' && qx.core.Init.getApplication() && qx.core.Init.getApplication().getUIItem(ClientLib.Data.Missions.PATH.BAR_NAVIGATION) && qx.core.Init.getApplication().getUIItem(ClientLib.Data.Missions.PATH.BAR_NAVIGATION).isVisible()) {
  3606. createMaelstromTools();
  3607. MaelstromTools.Base.getInstance().initialize();
  3608. } else {
  3609. setTimeout(MaelstromTools_checkIfLoaded, 1000);
  3610. }
  3611. } catch (e) {
  3612. console.log("MaelstromTools_checkIfLoaded: ", e);
  3613. }
  3614. }
  3615. setTimeout(MaelstromTools_checkIfLoaded, 1000);
  3616. };
  3617.  
  3618. try {
  3619. var MaelstromScript = document.createElement("script");
  3620. MaelstromScript.innerHTML = "(" + MaelstromTools_main.toString() + ")();";
  3621. MaelstromScript.type = "text/javascript";
  3622. document.getElementsByTagName("head")[0].appendChild(MaelstromScript);
  3623. } catch (e) {
  3624. console.log("MaelstromTools: init error: ", e);
  3625. }
  3626. })();