Greasy Fork is available in English.

C&C Tiberium Alliances Eldas - Combat Simulator

Combat Simulator used to plan and strategize attack before going into battle. This script based on Peluski17 Simulator script.

Ezt a szkriptet eltávolították.

// ==UserScript==
// @name 		C&C Tiberium Alliances  Eldas - Combat Simulator
// @description 	Combat Simulator used to plan and strategize attack before going into battle. This script based on Peluski17 Simulator script.
// @namespace      	http*://*.alliances.commandandconquer.com/*
// @include        	http*://*.alliances.commandandconquer.com/*
// @version 		4.0.0
// @author 		Elda1990
// @grant 		none
// ==/UserScript==

/**
 *	Although I am the author of this script, I want to also give credit to other authors who's methods and ideas are or might appear in this script. 
 * 	Credits: Topper42, Eferz98, KRS_L, PythEch, MrHIDEn, Panavia2, Deyhak, CodeEcho, 
 *	Matthias Fuchs, Enceladus, TheLuminary, Da Xue, Quor, WildKatana, Peluski17
*/ 

(function(){
	var injectFunction = function() 
	{
		function createClasses()
		{
			//This is the setup for a class. 
			/*qx.Class.define("EXAMPLE", 
			{
				type: "singleton",
				extend: qx.core.Object,
            
				construct: function()
				{
				},
				
				destruct: function()
				{
				},
				
				members: 
				{
				}
			});*/
			
			qx.Class.define("Simulator", 
			{
				type: "singleton",
				extend: qx.core.Object,
            
				construct: function()
				{
					//setup buttons
					try 
					{						
						armyBar = qx.core.Init.getApplication().getUIItem(ClientLib.Data.Missions.PATH.BAR_ATTACKSETUP);
						
						//Simulator Button//
						simBtn = new qx.ui.form.Button("Simulate");
						simBtn.set
						({
							alignY: "middle", 
							width: 60,
							height: 28,
							toolTipText: "Opens Simulation Screen.",
							appearance: "button-text-small"
						});
						simBtn.addListener("click", this.__openSimulatorWindow, this);
						
						armyBar.add(simBtn,{
							left: null,
							right: 58,
							bottom: 119
						});
						
						//Simulator Options Button//
						optionBtn = new qx.ui.form.Button("Options");
						optionBtn.set
						({
							alignY: "middle", 
							width: 60,
							height: 28,
							toolTipText: "Opens Simulator Options",
							appearance: "button-text-small"
						});
						optionBtn.addListener("click", this.__openOptionWindow, this);
						
						armyBar.add(optionBtn,{
							left: null,
							right: 58,
							bottom: 43
						});
						
						//Simulator Stats Button//
						statBtn = new qx.ui.form.Button("Stats");
						statBtn.set
						({
							alignY: "middle", 
							width: 60,
							height: 28,
							toolTipText: "Opens Simulator Stats Window",
							appearance: "button-text-small"
						});
						statBtn.addListener("click", this.__openStatWindow, this);
						
						armyBar.add(statBtn,{
							left: null,
							right: 58,
							bottom: 81
						});
						
						//Simulator Layout Button//
						layoutBtn = new qx.ui.form.Button("Layout");
						layoutBtn.set
						({
							alignY: "middle", 
							width: 60,
							height: 28,
							toolTipText: "Save/Load/Delete Unit Formations for current city",
							appearance: "button-text-small"
						});
						layoutBtn.addListener("click", this.__openLayoutWindow, this);
						//layoutBtn.setEnabled(false);
						armyBar.add(layoutBtn,{
							left: null,
							right: 58,
							bottom: 5
						});
						
						//Simulator Unlock Combat Button//	
						unlockCmtBtn = new qx.ui.form.Button("Unlock");
						unlockCmtBtn.set
						({
							alignY: "middle",
							width: 50,
							height: 50,
							toolTipText: "Unlock Combat Button",
							appearance: "button-text-small"
						});
						unlockCmtBtn.setOpacity(0.7);
						armyBar.add(unlockCmtBtn,{
							left: null,
							right: 7,
							bottom: 5
						});
						unlockCmtBtn.addListener("click", this.timeoutCmtBtn, this);
						
						//Simulator Unlock Repair Time Button//
						unlockRTBtn = new qx.ui.form.Button("Unlock");
						unlockRTBtn.set
						({
							alignY: "middle",
							width: 50,
							height: 50,
							toolTipText: "Unlock Repair Button",
							appearance: "button-text-small"
						});
						unlockRTBtn.setOpacity(0.7);
						
						armyBar.add(unlockRTBtn,{
							left: null,
							right: 7,
							bottom: 97
						});
						unlockRTBtn.addListener("click", this.timeoutRTBtn, this);
						
						playArea = qx.core.Init.getApplication().getUIItem(ClientLib.Data.Missions.PATH.OVL_PLAYAREA);
						//Formation Buttons//
						shiftUpBtn = new qx.ui.form.Button("?");
						shiftUpBtn.set
						({
							alignY: "middle",
							width: 30,
							height: 20,
							toolTipText: "Shifts units one space up",
							appearance: "button-text-small"
						});
						playArea.add(shiftUpBtn,{
							left: null,
							right: 70,
							bottom: 110
						});
						shiftUpBtn.addListener("click", function(){this.shiftFormation("u");}, this);
						shiftUpBtn.hide();
						
						shiftDownBtn = new qx.ui.form.Button("?");
						shiftDownBtn.set
						({
							alignY: "middle",
							width: 30,
							height: 20,
							toolTipText: "Shifts units one space down",
							appearance: "button-text-small"
						});
						
						playArea.add(shiftDownBtn,{
							left: null,
							right: 70,
							bottom: 70
						});
						shiftDownBtn.addListener("click", function(){this.shiftFormation("d");}, this);
						shiftDownBtn.hide();
						
						shiftLeftBtn = new qx.ui.form.Button("?");
						shiftLeftBtn.set
						({
							alignY: "middle",
							width: 30,
							height: 20,
							toolTipText: "Shifts units one space left",
							appearance: "button-text-small"
						});
						playArea.add(shiftLeftBtn,{
							left: null,
							right: 90,
							bottom: 90
						});
						shiftLeftBtn.addListener("click", function(){this.shiftFormation("l");}, this);
						shiftLeftBtn.hide();
						
						shiftRightBtn = new qx.ui.form.Button("?");
						shiftRightBtn.set
						({
							alignY: "middle",
							width: 30,
							height: 20,
							toolTipText: "Shifts units one space right",
							appearance: "button-text-small"
						});
						playArea.add(shiftRightBtn,{
							left: null,
							right: 50,
							bottom: 90
						});
						shiftRightBtn.addListener("click", function(){this.shiftFormation("r");}, this);
						shiftRightBtn.hide();
						
						mirrorBtn = new qx.ui.form.Button("M");
						mirrorBtn.set
						({
							alignY: "middle",
							width: 35,
							height: 35,
							toolTipText: "Mirrors current army formation layout",
							appearance: "button-text-small"
						});
						
						playArea.add(mirrorBtn,{
							left: null,
							right: 6,
							bottom: 160
						});
						mirrorBtn.addListener("click", function(){this.mirrorFormation();}, this);
						mirrorBtn.hide();
						
						//disableAllUnitsBtn = new qx.ui.form.Button("", "webfrontend/ui/common/icn_res_power.png");
						disableAllUnitsBtn = new qx.ui.form.Button("", "FactionUI/icons/icon_disable_unit.png");
						disableAllUnitsBtn.set
						({
							center: true,
							show: "icon",
							alignY: "middle",
							width: 35,
							height: 35,
							toolTipText: "Enables/Disables all units",
							appearance: "button-text-small"
						});
						playArea.add(disableAllUnitsBtn,{
							left: null,
							right: 6,
							bottom: 120
						});
						disableAllUnitsBtn.addListener("click", function(){this.shiftFormation("n");}, this);
						disableAllUnitsBtn.getChildControl("icon").set({ width : 20, height : 20, scale : true });
						disableAllUnitsBtn.hide();
						
						armyUndoBtn = new qx.ui.form.Button("", "FactionUI/icons/icon_refresh_funds.png");
						armyUndoBtn.set
						({
							center: true,
							show: "icon",
							alignY: "middle",
							width: 35,
							height: 35,
							toolTipText: "Undo's formation to previous saved formation. Save formations by hitting the Update or Simulate button.",
							appearance: "button-text-small"
						});
						
						playArea.add(armyUndoBtn,{
							left: null,
							right: 6,
							bottom: 200
						});
						armyUndoBtn.addListener("click", function(){this.undoCurrentFormation();}, this);
						armyUndoBtn.setEnabled(false);
						armyUndoBtn.hide();
						
						quickSaveBtn = new qx.ui.form.Button("QS");
						quickSaveBtn.set
						({
							alignY: "middle",
							width: 35,
							height: 35,
							toolTipText: "Saves the current layout without having to open the Formation Saver window. Does not make persistent.",
							appearance: "button-text-small"
						});
						
						playArea.add(quickSaveBtn,{
							left: null,
							right: 6,
							bottom: 240
						});
						quickSaveBtn.addListener("click", function(){Simulator.LayoutWindow.getInstance().saveNewLayout(true)}, this);
						quickSaveBtn.hide();
												
						//Simulator Back Button//
						replayBar = qx.core.Init.getApplication().getReportReplayOverlay();
						var backBtn = new qx.ui.form.Button("Back");
						backBtn.set
						({
							width: 50,
							height: 24,
							appearance: "button-text-small",
							toolTipText: "Return to Combat Setup"
						});
						backBtn.addListener("click", this.backToCombatSetup, this);
						replayBar.add(backBtn, {
							top: 37,
							left: 255
						});
						
						var replayStatBtn = new qx.ui.form.Button("Stats");
						replayStatBtn.set
						({
							width: 50,
							height: 24,
							appearance: "button-text-small",
							toolTipText: "Return to Combat Setup"
						});
						replayStatBtn.addListener("click", this.__openStatWindow, this);
						replayBar.add(replayStatBtn, {
							top: 7,
							left: 255
						});
						
						this.isSimButtonDisabled = false;
						this.isSimulation = false;
						this.armyTempFormations = new Array();
						this.armyTempIdx = 0;
						this.repairOneBtns = new Array();
					}
					catch(e)
					{
						console.log("Error setting up Simulator Constructor: " );
						console.log(e.toString());
					}
				},
				
				destruct: function()
				{
				},
				
				members: 
				{
					armyBar: null,
					playArea: null,
					replayBar: null,
					simBtn: null,
					optionBtn: null,
					statBtn: null,
					layoutBtn: null,
					unlockCmtBtn: null,
					unlockRTBtn: null,
					shiftUpBtn: null,
					shiftDownBtn: null,
					shiftLeftBtn: null,
					shiftRightBtn: null,
					backBtn: null,
					isSimButtonDisabled: null,
					disableAllUnitsBtn: null,
					armyTempFormations: null,
					armyTempIdx: null,
					armyUndoBtn: null,
					isSimulation: null,
					quickSaveBtn: null,
					
					/**
					 * This method initiates the visual simulation with no stats produced. If the player
					 * wants stats produced, then they should do it through the stats window.
					 */
					__openSimulatorWindow: function()
					{
						var city = ClientLib.Data.MainData.GetInstance().get_Cities().get_CurrentCity();
						if (city != null)
						{
							var ownCity = ClientLib.Data.MainData.GetInstance().get_Cities().get_CurrentOwnCity();
							
							this.isSimulation = true;
							this.saveTempFormation();
							
							localStorage.ta_sim_last_city = city.get_Id();
							
							ownCity.get_CityArmyFormationsManager().set_CurrentTargetBaseId(city.get_Id());
							ClientLib.API.Battleground.GetInstance().SimulateBattle();
							var app = qx.core.Init.getApplication();
							var battleground = ClientLib.Vis.VisMain.GetInstance().get_Battleground();
							
							app.getPlayArea().setView(ClientLib.Data.PlayerAreaViewMode.pavmCombatReplay, city.get_Id(), 0, 0);
							
							
							var autoSim = localStorage['autoSimulate'];
							
							if (typeof autoSim != 'undefined')
							{
								if (autoSim == "yes")
								{
									var speed = localStorage['simulateSpeed'];
									setTimeout(function() {
										battleground.RestartReplay();
										battleground.set_ReplaySpeed(parseInt(speed));
									}, 1000)
								}
							}
							
							if ( this.isSimButtonDisabled == false)
							{
								simBtn.setEnabled(false);
								var simTimer = 10000;
								this.disableSimulateButtonTimer(simTimer);
								
								if (typeof simStatBtn != "undefined")
								{
									simStatBtn.setEnabled(false);
									var simStatTimer = 10000;
									Simulator.StatWindow.getInstance().disableSimulateStatButtonTimer(simStatTimer);
								}
							}
							
							setTimeout(function() {
								var battleDuration = battleground.get_BattleDuration();
								battleDuration = Simulator.StatWindow.getInstance().formatBattleDurationTime(battleDuration);
								Simulator.StatWindow.getInstance().__labelMiscBattleDuration.setValue(battleDuration);
							}, 1000);
							
							if (simReplayBtn.getEnabled() == false)
							{
								simReplayBtn.setEnabled(true);
							}
						}	
					},
					
					__openOptionWindow: function()
					{
						try
						{
							if (Simulator.OptionWindow.getInstance().isVisible())
							{
								console.log("Closing Option Window");
								Simulator.OptionWindow.getInstance().close();
							}
							else
							{
								console.log("Opening Option Window");
								Simulator.OptionWindow.getInstance().open();
							}
						}
						catch(e)
						{
							console.log("Error Opening or Closing Option Window");
							console.log(e.toString());
						}
					},
					
					__openStatWindow: function()
					{
						try
						{
							if (Simulator.StatWindow.getInstance().isVisible())
							{
								console.log("Closing Stat Window");
								Simulator.StatWindow.getInstance().close();
							}
							else
							{
								console.log("Opening Stat Window");
								Simulator.StatWindow.getInstance().open();
                                Simulator.StatWindow.getInstance().calcResources();
							}
						}
						catch(e)
						{
							console.log("Error Opening or Closing Stat Window");
							console.log(e.toString());
						}
					},
					
					__openLayoutWindow: function()
					{
						try
						{
							if (Simulator.LayoutWindow.getInstance().isVisible())
							{
								console.log("Closing Layout Window");
								Simulator.LayoutWindow.getInstance().close();
							}
							else
							{
								console.log("Opening LayoutWindow");
								Simulator.LayoutWindow.getInstance().updateLayoutList();
								Simulator.LayoutWindow.getInstance().layoutTextBox.setValue("");
								Simulator.LayoutWindow.getInstance().persistentCheck.setValue(false);
								Simulator.LayoutWindow.getInstance().open();
							}
						}
						catch(e)
						{
							console.log("Error Opening or Closing Layout Window");
							console.log(e.toString());
						}
					},
					
					__openToolsWindow: function()
					{
						//Might need to be implemented later on.
					},
					
					attachNetEvent: function()
					{
						console.log("Need to assign correct function!");
					},
					
					formatNumbersCompact: function()
					{
						console.log("Need to assign correct function!");
					},
					
					GetUnitMaxHealth: function()
					{
						console.log("Need to assign correct function!");
						return -1;                
					},
					
					saveTempFormation: function()
					{
						try
						{
							if (this.armyTempFormations.length != 0)
							{
								var currForm = this.getCityPreArmyUnits().get_ArmyUnits().l;
								
								for (var i = 0; i < currForm.length; i++)
								{
									var lastForm = this.armyTempFormations[this.armyTempIdx][i];
									if ( (currForm[i].get_CoordX() != lastForm.x) || (currForm[i].get_CoordY() != lastForm.y))
									{
										break;
									}
									else if ((i + 1) == currForm.length )
									{
										return;
									}
								}
							}
							
							var formation = new Array();
							var unitList = this.getCityPreArmyUnits().get_ArmyUnits().l;
							
							for (var i = 0; i < unitList.length; i++)
							{
								var unit = unitList[i];
								var unitInfo = {};
								unitInfo.x = unit.get_CoordX();
								unitInfo.y = unit.get_CoordY();
								unitInfo.id = unit.get_Id();
								unitInfo.enabled = unit.get_Enabled();
								
								formation.push(unitInfo);
							}
							
							this.armyTempFormations.push(formation);
							this.armyTempIdx = this.armyTempFormations.length - 1;
							if (this.armyTempFormations.length > 1)
								armyUndoBtn.setEnabled(true);
						}
						catch(e)
						{
							console.log("Error Saving Temp Formation");
							console.log(e.toString());
						}
					},
					
					undoCurrentFormation: function()
					{
						try
						{
							this.restoreFormation(this.armyTempFormations[(this.armyTempIdx - 1)]);
							
							//get rid of last element now that we have undone it.
							this.armyTempFormations.splice(this.armyTempIdx, 1);
							this.armyTempIdx--;
							
							if (this.armyTempFormations.length == 1)
								armyUndoBtn.setEnabled(false);
						}
						catch(e)
						{
							console.log("Error undoing formation");
							console.log(e.toString());
						}
					},
					
					/*
					 * Mirrors across the X Axis (4 is axis on grid 0-9)
					 */
					mirrorFormation: function()
					{
						try
						{
							var units = this.getCityPreArmyUnits();
							var unitsList = this.getCityPreArmyUnits().get_ArmyUnits().l;
							var mirror = new Array();
							
							for (var i = 0; i < unitsList.length; i++)
							{
								var unit = unitsList[i];
								var armyUnit = {};
								
								//do the mirroring
								var x = unit.get_CoordX();
								var distanceX = x - 4; //from center (4)
								if (distanceX < 0)
								{
									x = (x - distanceX) + (-1 * distanceX);
								}
								else if (distanceX > 0)
								{
									x = (x - distanceX) - distanceX;
								}
								
								armyUnit.x = x;
								armyUnit.y = unit.get_CoordY();
								armyUnit.id = unit.get_Id();
								armyUnit.enabled = unit.get_Enabled();
								
								mirror.push(armyUnit);
							}
							
							this.restoreFormation(mirror);
						}
						catch(e)
						{
							console.log("Error Mirroring Formation");
							console.log(e);
						}
					},
					
					/**
					 * Code from one of the previous authors of an older simulator version. If anyone knows the true author please let me know.
					 */
					shiftFormation: function(direction)
					{
						try
						{							
							console.log("Shifting Unit Formation");
							var v_shift = 0;
							var h_shift = 0;
							
							//Determines shift direction 
							if (direction == "u") var v_shift = -1;
							if (direction == "d") var v_shift = 1;
							if (direction == "l") var h_shift = -1;
							if (direction == "r") var h_shift = 1;
							//No need to continue
							if (v_shift == 0 && h_shift == 0 && direction != "n")
								return;
								
							var units = this.getCityPreArmyUnits().get_ArmyUnits().l;
							
							var newLayout = [];
							for (var i = 0;	(i < units.length); i++) 
							{
								var unit = units[i];
								var armyUnit = {};
								var x = unit.get_CoordX() + h_shift;
								switch (x) {
									case 9:
									x = 0;
									break;
									case -1:
									x = 8;
									break;
								}
								var y = unit.get_CoordY() + v_shift;
								switch (y) {
									case 4:
									y = 0;
									break;
									case -1:
									y = 3;
									break;
								}
								armyUnit.x = x;
								armyUnit.y = y;
								armyUnit.id = unit.get_Id();
								
								//For enabling/disabling all units
								if (direction == "n")
								{
									if (typeof localStorage['allUnitsDisabled'] != 'undefined')
									{
										if (localStorage['allUnitsDisabled'] == "yes")
										{
											armyUnit.enabled = unit.set_Enabled(false);
										}
										else
										{
											armyUnit.enabled = unit.set_Enabled(true);
										}
									}
									else
									{
										armyUnit.enabled = unit.set_Enabled(false);
									}
								}
								armyUnit.enabled = unit.get_Enabled();
								newLayout.push(armyUnit);
							}
							//Change disable button to opposite 
							if (direction == "n")
							{
								if (localStorage['allUnitsDisabled'] == "yes")
									localStorage['allUnitsDisabled'] = "no";
								else
									localStorage['allUnitsDisabled'] = "yes";
							}
							this.restoreFormation(newLayout);
						}
						catch(e)
						{
							console.log("Error Shifting Units");
							console.log(e.toString());
						}
					},
					
					restoreFormation: function(layout)
					{
						try
						{
							var sUnits = layout;
							
							var units = this.getCityPreArmyUnits();
							var units_list = units.get_ArmyUnits().l;
							
							for (var idx = 0; idx < sUnits.length; idx++) 
							{
								var saved_unit = sUnits[idx];
								var uid = saved_unit.id;
								for (var i = 0; i < units_list.length; i++) 
								{
									if (units_list[i].get_Id() === uid) 
									{
										units_list[i].MoveBattleUnit(saved_unit.x, saved_unit.y);
										if (saved_unit.enabled === undefined) 
											units_list[i].set_Enabled(true);
										else 
											units_list[i].set_Enabled(saved_unit.enabled);
									}
								}
							}
							units.UpdateFormation(true);
						}
						catch(e)
						{
							console.log("Error Restoring Formation");
							console.log(e.toString());
						}
					},
					
					getCityPreArmyUnits: function()
					{
						var city = ClientLib.Data.MainData.GetInstance().get_Cities().get_CurrentCity();
						var ownCity = ClientLib.Data.MainData.GetInstance().get_Cities().get_CurrentOwnCity();
						var formationManager = ownCity.get_CityArmyFormationsManager();
						ownCity.get_CityArmyFormationsManager().set_CurrentTargetBaseId(city.get_Id());
						
						return formationManager.GetFormationByTargetBaseId(formationManager.get_CurrentTargetBaseId());
					},
					
					timeoutCmtBtn: function()
					{
						armyBar.remove(unlockCmtBtn);
						setTimeout(function() {
							armyBar.add(unlockCmtBtn,{
								left: null,
								right: 7,
								bottom: 5
							});
						}, 2000);
					},
					
					timeoutRTBtn: function()
					{
						armyBar.remove(unlockRTBtn);
						setTimeout(function() {
							armyBar.add(unlockRTBtn,{
								left: null,
								right: 7,
								bottom: 97
							});
						}, 2000);
					},
					
					backToCombatSetup: function()
					{
						var app = qx.core.Init.getApplication();
						var player_cities = ClientLib.Data.MainData.GetInstance().get_Cities();
						var current_city = player_cities.get_CurrentCity();
						try 
						{
							//This brings the player back to viewing the enemies defense setup PlayArea
							app.getPlayArea().setView(ClientLib.Data.PlayerAreaViewMode.pavmCombatSetupDefense, localStorage.ta_sim_last_city, 0, 0);
						} 
						catch (e) 
						{
							console.log("Error closing Simulation Window");
							console.log(e.toString());
						}	
					},
					
					disableSimulateButtonTimer: function(timer)
					{
						try
						{
							if ( timer >= 1000)
							{
								this.isSimButtonDisabled =true;
								simBtn.setLabel(Math.floor(timer/1000));
								timer -= 1000;
								setTimeout(function () {
									Simulator.getInstance().disableSimulateButtonTimer(timer);
								}, 1000)
							}
							else
							{
								setTimeout(function () {
									simBtn.setEnabled(true);
									if (Simulator.OptionWindow.getInstance()._buttonSizeCB.getValue())
										simBtn.setLabel("Simulate");
									else
										simBtn.setLabel("S");	
								}, timer)
								this.isSimButtonDisabled = false;
							}
						}
						catch(e)
						{
							console.log("Error disabling simulator button");
							console.log(e.toString());
						}
					}
				}
			});
			
			qx.Class.define("Simulator.StatWindow", 
			{
				type: "singleton",
				extend:	qx.ui.window.Window,
				construct: function()
				{
					this.base(arguments);
					this.setLayout(new qx.ui.layout.VBox());
					
					this.set({
						width: 220,
						caption: "Simulator Stats",
						padding: 2,
						allowMaximize: false,
						showMaximize: false,
						allowMinimize: false,
						showMinimize: false,
						
					});
					
					this.setResizable(false, true, false, true);
					if (typeof localStorage['statWindowPosLeft'] != 'undefined')
					{
						var left = parseInt(localStorage['statWindowPosLeft']);
						var top = parseInt(localStorage['statWindowPosTop']);
						this.moveTo(left, top);
					}
					else
					{
						this.moveTo(125,30);
					}

					//Enemy Health Section//
					var enemyHealthHeader = new qx.ui.container.Composite(new qx.ui.layout.VBox()).set({ decorator: "pane-light-opaque"});
					var enemyHealthTitle = new qx.ui.basic.Label("Enemy Base Health").set({ alignX: "center", alignY: "top", font: "font_size_14_bold"});
					enemyHealthHeader.add(enemyHealthTitle);
					this.add(enemyHealthHeader);
					
					var enemyHealth = new qx.ui.container.Composite(new qx.ui.layout.HBox(2));
					enemyHealth.setThemedFont("bold");
					var enemyHealthBox = new qx.ui.container.Composite(new qx.ui.layout.VBox(5)).set({ width: 70, padding: 5, decorator: "pane-light-opaque"});
					var eHLabelOverall = new qx.ui.basic.Label("Overall:");
					var eHLabelBase = new qx.ui.basic.Label("Base:");
					var eHLabelDefense = new qx.ui.basic.Label("Defense:");
					var eHLabelCY = new qx.ui.basic.Label("Con.Yard:");
					var eHLabelDF = new qx.ui.basic.Label("Def.Fac:");
					enemyHealthBox.add(eHLabelOverall);
					enemyHealthBox.add(eHLabelBase);
					enemyHealthBox.add(eHLabelDefense);
					enemyHealthBox.add(eHLabelCY);
					enemyHealthBox.add(eHLabelDF);
					enemyHealth.add(enemyHealthBox);
					
					this.__labelEnemyOverallHealth = new Array();
					this.__labelEnemyBaseHealth = new Array();
					this.__labelEnemyDefenseHealth = new Array();
					this.__labelEnemyCYHealth = new Array();
					this.__labelEnemyDFHealth = new Array();
					
					var enemyHealthValues = new qx.ui.container.Composite(new qx.ui.layout.VBox(5)).set({ alignX: "center", width: 90, padding: 5, decorator: "pane-light-opaque"});
					this.__labelEnemyOverallHealth = new qx.ui.basic.Label("-").set({ alignX: "right"});
					this.__labelEnemyBaseHealth = new qx.ui.basic.Label("-").set({ alignX: "right"});
					this.__labelEnemyDefenseHealth = new qx.ui.basic.Label("-").set({ alignX: "right"});
					this.__labelEnemyCYHealth = new qx.ui.basic.Label("-").set({ alignX: "right"});
					this.__labelEnemyDFHealth = new qx.ui.basic.Label("-").set({ alignX: "right"});
					enemyHealthValues.add(this.__labelEnemyOverallHealth);
					enemyHealthValues.add(this.__labelEnemyBaseHealth);
					enemyHealthValues.add(this.__labelEnemyDefenseHealth);
					enemyHealthValues.add(this.__labelEnemyCYHealth);
					enemyHealthValues.add(this.__labelEnemyDFHealth);
					enemyHealth.add(enemyHealthValues, { flex: 1 });
					this.add(enemyHealth);
					
					//Player Repair Section//
					var playerRepairHeader = new qx.ui.container.Composite(new qx.ui.layout.VBox()).set({ decorator: "pane-light-opaque"});
					var playerRepairTitle = new qx.ui.basic.Label("Repair Times").set({ alignX: "center", alignY: "top", font: "font_size_14_bold"});
					playerRepairHeader.add(playerRepairTitle);
					this.add(playerRepairHeader);
					
					var playerRepair = new qx.ui.container.Composite(new qx.ui.layout.HBox(2));
					playerRepair.setThemedFont("bold");
					var playerRepairBox = new qx.ui.container.Composite(new qx.ui.layout.VBox(5)).set({ width: 70, padding: 5, decorator: "pane-light-opaque"});
					var pRLabelStorage = new qx.ui.basic.Label("Storage:");
					var pRLabelOverall = new qx.ui.basic.Label("Overall:");
					var pRLabelInf = new qx.ui.basic.Label("Infantry:");
					var pRLabelVehi = new qx.ui.basic.Label("Vehicle:");
					var pRLabelAir = new qx.ui.basic.Label("Aircraft:");
					playerRepairBox.add(pRLabelStorage);
					playerRepairBox.add(pRLabelOverall);
					playerRepairBox.add(pRLabelInf);
					playerRepairBox.add(pRLabelVehi);
					playerRepairBox.add(pRLabelAir);
					playerRepair.add(playerRepairBox);
					
					var playerRepairValues = new qx.ui.container.Composite(new qx.ui.layout.VBox(5)).set({ alignX: "center", width: 90, padding: 5, decorator: "pane-light-opaque"});
					this.__labelRepairStorage = new qx.ui.basic.Label("-").set({ alignX: "right"});
					this.__labelRepairOverall = new qx.ui.basic.Label("-").set({ alignX: "right"});
					this.__labelRepairInf = new qx.ui.basic.Label("-").set({ alignX: "right"});
					this.__labelRepairVehi = new qx.ui.basic.Label("-").set({ alignX: "right"});
					this.__labelRepairAir = new qx.ui.basic.Label("-").set({ alignX: "right"});
					playerRepairValues.add(this.__labelRepairStorage);
					playerRepairValues.add(this.__labelRepairOverall);
					playerRepairValues.add(this.__labelRepairInf);
					playerRepairValues.add(this.__labelRepairVehi);
					playerRepairValues.add(this.__labelRepairAir);
					playerRepair.add(playerRepairValues, { flex: 1 });
					this.add(playerRepair);
					
					//MISC Section//
					var miscHeader = new qx.ui.container.Composite(new qx.ui.layout.VBox()).set({ decorator: "pane-light-opaque"});
					var miscTitle = new qx.ui.basic.Label("Misc").set({ alignX: "center", alignY: "top", font: "font_size_14_bold"});
					miscHeader.add(miscTitle);
					this.add(miscHeader);
					
					var misc = new qx.ui.container.Composite(new qx.ui.layout.HBox(2));
					misc.setThemedFont("bold");
					var miscBox = new qx.ui.container.Composite(new qx.ui.layout.VBox(5)).set({ width: 70, padding: 5, decorator: "pane-light-opaque"});
					var miscOutcome = new qx.ui.basic.Label("Outcome:");
					var miscBattleDuration = new qx.ui.basic.Label("Duration:");
					miscBox.add(miscOutcome);
					miscBox.add(miscBattleDuration);
					misc.add(miscBox);
					
					this.__labelMiscOutcome = new Array();
					this.__labelMiscBattleDuration = new Array();
					
					var miscValues = new qx.ui.container.Composite(new qx.ui.layout.VBox(5)).set({ alignX: "center", width: 90, padding: 5, decorator: "pane-light-opaque"});
					this.__labelMiscOutcome = new qx.ui.basic.Atom("Unknown", null).set({ allowGrowX: false, alignX: "right"});
					this.__labelMiscBattleDuration = new qx.ui.basic.Label("0:00").set({ alignX: "right"});
					miscValues.add(this.__labelMiscOutcome);
					miscValues.add(this.__labelMiscBattleDuration);
					misc.add(miscValues, { flex: 1 });
					this.add(misc);	
					
					//Battle Loot Section//
					var battleLootHeader = new qx.ui.container.Composite(new qx.ui.layout.VBox()).set({ decorator: "pane-light-opaque"});
					var battleLootTitle = new qx.ui.basic.Label("Loot from Battle").set({ alignX: "center", alignY: "top", font: "font_size_14_bold"});
					battleLootHeader.add(battleLootTitle);
					this.add(battleLootHeader);
					
					
					var battleLoot = new qx.ui.container.Composite(new qx.ui.layout.HBox(2));
					battleLoot.setThemedFont("bold");
					var battleLootBox = new qx.ui.container.Composite(new qx.ui.layout.VBox(5)).set({ width: 70, padding: 5, decorator: "pane-light-opaque"});
					var battleLootTib = new qx.ui.basic.Atom(null, "webfrontend/ui/common/icn_res_tiberium.png");
					var battleLootCry = new qx.ui.basic.Atom(null, "webfrontend/ui/common/icn_res_chrystal.png");
					var battleLootCred = new qx.ui.basic.Atom(null, "webfrontend/ui/common/icn_res_dollar.png");
					var battleLootRP = new qx.ui.basic.Atom(null, "webfrontend/ui/common/icn_res_research_mission.png");
					//var battleLootTotal = new qx.ui.basic.Atom(null, "webfrontend/ui/icons/icon_item.png");
					var battleLootTotal = new qx.ui.basic.Atom(null, "webfrontend/ui/common/icn_build_slots.png");
					battleLootTib.setToolTipText("Tiberium");
					battleLootCry.setToolTipText("Crystals");
					battleLootCred.setToolTipText("Credits");
					battleLootRP.setToolTipText("Research Points");
					battleLootTotal.setToolTipText("Total Loot");
					battleLootTib.getChildControl("icon").set({ width : 23, height : 23, scale : true }); 
					battleLootCry.getChildControl("icon").set({ width : 23, height : 23, scale : true }); 
					battleLootCred.getChildControl("icon").set({ width : 23, height : 23, scale : true }); 
					battleLootRP.getChildControl("icon").set({ width : 23, height : 23, scale : true }); 
					battleLootTotal.getChildControl("icon").set({ width : 23, height : 23, scale : true }); 
					battleLootBox.add(battleLootTib);
					battleLootBox.add(battleLootCry);
					battleLootBox.add(battleLootCred);
					battleLootBox.add(battleLootRP);
					battleLootBox.add(battleLootTotal);
					battleLoot.add(battleLootBox);
					
					this.__labelBattleLootTotal = new Array();
					this.__labelBattleLootTib = new Array();
					this.__labelBattleLootCry = new Array();
					this.__labelBattleLootCred = new Array();
					this.__labelBattleLootRP = new Array();
					
					var battleLootValues = new qx.ui.container.Composite(new qx.ui.layout.VBox(5)).set({ alignX: "center", width: 90, padding: 5, decorator: "pane-light-opaque"});
					this.__labelBattleLootTib = new qx.ui.basic.Label("-").set({ alignX: "right", padding: 3});
					this.__labelBattleLootCry = new qx.ui.basic.Label("-").set({ alignX: "right", padding: 3});
					this.__labelBattleLootCred = new qx.ui.basic.Label("-").set({ alignX: "right", padding: 3});
					this.__labelBattleLootRP = new qx.ui.basic.Label("-").set({ alignX: "right", padding: 3});
					this.__labelBattleLootTotal = new qx.ui.basic.Label("-").set({ alignX: "right", padding: 3});
					battleLootValues.add(this.__labelBattleLootTib);
					battleLootValues.add(this.__labelBattleLootCry);
					battleLootValues.add(this.__labelBattleLootCred);
					battleLootValues.add(this.__labelBattleLootRP);
					battleLootValues.add(this.__labelBattleLootTotal);
					battleLoot.add(battleLootValues, { flex: 1 });
					this.add(battleLoot);
					
					//Simulate Button//
					var simButton = new qx.ui.container.Composite(new qx.ui.layout.HBox(5)).set({ padding: 5, decorator: "pane-light-opaque"});
					this.add(simButton);
					
					simStatBtn = new qx.ui.form.Button("Update").set({allowGrowX: false});
					simStatBtn.setToolTipText("Updates Simulation Stats");
					simStatBtn.addListener("click", this.simulateStats, this);
					
					simReplayBtn = new qx.ui.form.Button("Replay").set({allowGrowX: false});
					simReplayBtn.setToolTipText("Shows Replay of last simulation");
					simReplayBtn.addListener("click", this.doSimReplay, this);
					
					simReplayBtn.setEnabled(false);
					
					simButton.add(simStatBtn, {width: "50%"});
					simButton.add(simReplayBtn, {width: "50%"});
					
					//Add Header Events//
					enemyHealthHeader.addListener("click", function()
					{
						if (enemyHealth.isVisible())
							enemyHealth.exclude();
						else
							enemyHealth.show();
					}, this);
					
					playerRepairHeader.addListener("click", function()
					{
						if (playerRepair.isVisible())
							playerRepair.exclude();
						else
							playerRepair.show();
					}, this);
					
					miscHeader.addListener("click", function()
					{
						if (misc.isVisible())
							misc.exclude();
						else
							misc.show();
					}, this);
					
					battleLootHeader.addListener("click", function()
					{
						if (battleLoot.isVisible())
							battleLoot.exclude();
						else
							battleLoot.show();
					}, this);
					
					if (typeof localStorage['hideHealth'] != 'undefined')
					{
						if (localStorage['hideHealth'] == "yes")
							enemyHealth.exclude();
					}
					
					if (typeof localStorage['hideRepair'] != 'undefined')
					{
						if (localStorage['hideRepair'] == "yes")
							playerRepair.exclude();
					}
					
					if (typeof localStorage['hideMisc'] != 'undefined')
					{
						if (localStorage['hideMisc'] == "yes")
							misc.exclude();
					}
					
					if (typeof localStorage['hideLoot'] != 'undefined')
					{
						if (localStorage['hideLoot'] == "yes")
							battleLoot.exclude();
					}
					
					this.isSimStatButtonDisabled = false;
					
					Simulator.getInstance().attachNetEvent(ClientLib.API.Battleground.GetInstance(), "OnSimulateBattleFinished", ClientLib.API.OnSimulateBattleFinished, this, this.__OnSimulateBattleFinished);					
				},
				
				destruct: function()
				{
				},
				
				members: 
				{
					simStatBtn: null,
					simReplayBtn: null,
					__labelEnemyOverallHealth: null,
					__labelEnemyBaseHealth: null,
					__labelEnemyDefenseHealth: null,
					__labelEnemyCYHealth: null,
					__labelEnemyDFHealth: null,
					__labelRepairOverall: null,
					__labelRepairInf: null,
					__labelRepairVehi: null,
					__labelRepairAir: null,
					__labelBattleLootTotal: null,
					__labelBattleLootTib: null,
					__labelBattleLootCry: null,
					__labelBattleLootCred: null,
					__labelBattleLootRP: null,
					__labelMiscOutcome: null,
					__labelMiscBattleDuration: null,
					isSimStatButtonDisabled: null,
					__labelRepairStorage: null,
					
					simulateStats: function()
					{
						console.log("Simulating Stats");
						var city = ClientLib.Data.MainData.GetInstance().get_Cities().get_CurrentCity();
						if (city != null)
						{			
							Simulator.getInstance().isSimulation = true;						
							Simulator.getInstance().saveTempFormation();
							localStorage.ta_sim_last_city = city.get_Id();
							var ownCity = ClientLib.Data.MainData.GetInstance().get_Cities().get_CurrentOwnCity();
							ownCity.get_CityArmyFormationsManager().set_CurrentTargetBaseId(city.get_Id());
							ClientLib.API.Battleground.GetInstance().SimulateBattle();
							var battleground = ClientLib.Vis.VisMain.GetInstance().get_Battleground();
							
							//Disable Simulate Button
							if ( this.isSimStatButtonDisabled == false )
							{
								simStatBtn.setEnabled(false);
								var simStatTimer = 10000;
								var simStatTimeout = this.disableSimulateStatButtonTimer(simStatTimer);
								
								simBtn.setEnabled(false);
								var simTimer = 10000;
								Simulator.getInstance().disableSimulateButtonTimer(simTimer);
							}
							
							setTimeout(function() {
								var battleDuration = battleground.get_BattleDuration();
								battleDuration = Simulator.StatWindow.getInstance().formatBattleDurationTime(battleDuration);
								Simulator.StatWindow.getInstance().__labelMiscBattleDuration.setValue(battleDuration);
							}, 1000);
							
							if (simReplayBtn.getEnabled() == false)
								simReplayBtn.setEnabled(true);
						}
					},
					
					doSimReplay: function()
					{
						try
						{
							Simulator.getInstance().isSimulation = true;
							var battleground = ClientLib.Vis.VisMain.GetInstance().get_Battleground();
							var app = qx.core.Init.getApplication();
							app.getPlayArea().setView(ClientLib.Data.PlayerAreaViewMode.pavmCombatReplay, localStorage.ta_sim_last_city, 0, 0);
							
							var autoSim = localStorage['autoSimulate'];
							
							if (typeof autoSim != 'undefined')
							{
								if (autoSim == "yes")
								{
									var speed = localStorage['simulateSpeed'];
									setTimeout(function() {
										battleground.RestartReplay();
										battleground.set_ReplaySpeed(parseInt(speed));
									}, 1000)
								}
							}
						}
						catch(e)
						{
							console.log("Error attempting to show Simulation Replay");
							console.log(e.toString());
						}
					},
					
					__OnSimulateBattleFinished: function(data) 
					{
						this.getSimulationInfo(data);
					},
					
					formatBattleDurationTime: function(time)
					{
						var seconds = time / 1000;
						var minutes = seconds / 60;
						minutes = Math.round(minutes - 0.5);
						seconds = Math.round((seconds - 0.5) - (minutes * 60));
						
						if( seconds < 10)
						{
							seconds = "0" + seconds;
						}
						return minutes + ":" + seconds;
					},
					
					calculateRepairCosts: function(id, level, sHealth, eHealth, mHealth)
					{
						repairCosts = {"RT": 0, "C": 0};
						var dmgRatio = 1;
						if (sHealth != eHealth)
						{
							if (eHealth > 0)
							{
								dmgRatio = ((sHealth - eHealth) / 16) / mHealth;
							}
							else
							{
								dmgRatio = (sHealth / 16) / mHealth;
							}
							//var currOwnCity = ClientLib.Data.MainData.GetInstance().get_Cities().get_CurrentOwnCity();
							var costs = ClientLib.API.Util.GetUnitRepairCosts(level, id, dmgRatio);

							for (var idx = 0; idx < costs.length; idx++)
							{
								var uCosts = costs[idx];
								var cType = parseInt(uCosts.Type);
								switch (cType) 
								{
									case ClientLib.Base.EResourceType.Crystal:
										repairCosts["C"] += uCosts.Count;
										break;
									case ClientLib.Base.EResourceType.RepairChargeBase:
									case ClientLib.Base.EResourceType.RepairChargeInf:
									case ClientLib.Base.EResourceType.RepairChargeVeh:
									case ClientLib.Base.EResourceType.RepairChargeAir:
										repairCosts