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-28 提交的版本。查看 最新版本

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