MaelstromTools Dev

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.

目前為 2015-11-14 提交的版本,檢視 最新版本

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