Click here to Skip to main content
15,895,557 members
Articles / Programming Languages / C#

Mars Mission (5) : the Chemistry of Fuel

Rate me:
Please Sign up or sign in to vote.
4.70/5 (10 votes)
18 Jul 2011CPOL37 min read 29.4K   6.2K   17  
adding chemical elements the ships can use as fuel, and a new auto-pilot feature
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Xml;
using System.Windows.Forms;

namespace Mars_Mission
{
	public class formEditContainer : Form
	{
		classResourceObject cResObject = null;
		private CK_Controls.TextBox_Numeric ntxtCapacity_Energy;
		private Label lblResourceType;
		private Label lblCapacity_Energy;
		private DataGridView dgvContents;
		DataGridViewRow dgvSelectedRow = null;
		List<classChemical> lcChemicals = null;

		public classResourceObject ResourceObject
		{
			get { return cResObject; }
			set
			{
				if (cResObject != value)
				{
					cResObject = value;
					if (cResObject != null)
					{
						initDGV();
						ntxtCapacity_Chemical.Value = cResObject.cChemicalInventory.Capacity;
						ntxtCapacity_Energy.Value = cResObject.cEnergyInventory.getCapacity(enuEnergy.eVolt);
					}
					else
					{
						ntxtCapacity_Chemical.Value = 0;
						ntxtCapacity_Energy.Value = 0;
						dgvContents.Rows.Clear();
					}
				}
			}
		}

		void initDGV()
		{
			dgvContents.Rows.Clear();
			for (int intResObjCounter = 0; intResObjCounter < cResObject.cObjContainer.lcResourceObjects.Count; intResObjCounter++)
			{
				dgvContents.Rows.Add();
				DataGridViewRow dgvRow = dgvContents.Rows[dgvContents.Rows.Count - 2];
				
				dgvRow.Cells[0].Value = enuResource_State.solid.ToString();
				dgvRow.Cells[1].Value = cResObject.cObjContainer.lcResourceObjects[intResObjCounter].eResource.ToString();
				dgvRow.Cells[2].Value = "1";
			}

			for (int intChemCounter = 0; intChemCounter < cResObject.cChemicalInventory.lcInventory.Count; intChemCounter++)
			{
				dgvContents.Rows.Add();
				DataGridViewRow dgvRow = dgvContents.Rows[dgvContents.Rows.Count - 2];

				dgvRow.Cells[0].Value = enuResource_State.chemical.ToString();
				dgvRow.Cells[1].Value = cResObject.cChemicalInventory.lcInventory[intChemCounter].Chemical.Formula;
				dgvRow.Cells[2].Value = cResObject.cChemicalInventory.lcInventory[intChemCounter].Quantity.ToString();
			}

			for (enuEnergy eEnergyCounter = (enuEnergy)0; eEnergyCounter < enuEnergy._numEnergy; eEnergyCounter++)
			{
				if (cResObject.cEnergyInventory.Available(eEnergyCounter) > 0)
				{
					dgvContents.Rows.Add();
					DataGridViewRow dgvRow = dgvContents.Rows[dgvContents.Rows.Count - 2];

					dgvRow.Cells[0].Value = enuResource_State.energy.ToString();
					dgvRow.Cells[1].Value = eEnergyCounter.ToString();
					dgvRow.Cells[2].Value = cResObject.cEnergyInventory.Available(eEnergyCounter).ToString();
				}
			}
		}

		private void InitializeComponent()
		{
			this.ntxtCapacity_Energy = new CK_Controls.TextBox_Numeric();
			this.lblResourceType = new System.Windows.Forms.Label();
			this.lblCapacity_Energy = new System.Windows.Forms.Label();
			this.dgvContents = new System.Windows.Forms.DataGridView();
			this.colState = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.colResourceType = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.colQuantity = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.cmbState = new System.Windows.Forms.ComboBox();
			this.cmbType = new System.Windows.Forms.ComboBox();
			this.ntxtQuantity = new CK_Controls.TextBox_Numeric();
			this.lblCapacity_Chemical = new System.Windows.Forms.Label();
			this.ntxtCapacity_Chemical = new CK_Controls.TextBox_Numeric();
			this.btnOk = new System.Windows.Forms.Button();
			this.btnResource_Add = new System.Windows.Forms.Button();
			this.btnResource_Delete = new System.Windows.Forms.Button();
			((System.ComponentModel.ISupportInitialize)(this.dgvContents)).BeginInit();
			this.SuspendLayout();
			// 
			// ntxtCapacity_Energy
			// 
			this.ntxtCapacity_Energy.BackColor = System.Drawing.Color.White;
			this.ntxtCapacity_Energy.Background_Dull = System.Drawing.Color.White;
			this.ntxtCapacity_Energy.Background_Highlight = System.Drawing.Color.Yellow;
			this.ntxtCapacity_Energy.ForeColor = System.Drawing.Color.Black;
			this.ntxtCapacity_Energy.Foreground_Dull = System.Drawing.Color.Black;
			this.ntxtCapacity_Energy.Foreground_Highlight = System.Drawing.Color.Black;
			this.ntxtCapacity_Energy.Location = new System.Drawing.Point(93, 25);
			this.ntxtCapacity_Energy.Max = 1.8446744073709552E+19D;
			this.ntxtCapacity_Energy.Min = 0D;
			this.ntxtCapacity_Energy.Name = "ntxtCapacity_Energy";
			this.ntxtCapacity_Energy.Size = new System.Drawing.Size(100, 20);
			this.ntxtCapacity_Energy.TabIndex = 0;
			this.ntxtCapacity_Energy.Text = "0";
			this.ntxtCapacity_Energy.Value = 0D;
			// 
			// lblResourceType
			// 
			this.lblResourceType.AutoSize = true;
			this.lblResourceType.Location = new System.Drawing.Point(1, 9);
			this.lblResourceType.Name = "lblResourceType";
			this.lblResourceType.Size = new System.Drawing.Size(71, 13);
			this.lblResourceType.TabIndex = 1;
			this.lblResourceType.Text = "resource type";
			// 
			// lblCapacity_Energy
			// 
			this.lblCapacity_Energy.AutoSize = true;
			this.lblCapacity_Energy.Location = new System.Drawing.Point(1, 28);
			this.lblCapacity_Energy.Name = "lblCapacity_Energy";
			this.lblCapacity_Energy.Size = new System.Drawing.Size(86, 13);
			this.lblCapacity_Energy.TabIndex = 2;
			this.lblCapacity_Energy.Text = "Energy capacity ";
			// 
			// dgvContents
			// 
			this.dgvContents.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
			this.dgvContents.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
            this.colState,
            this.colResourceType,
            this.colQuantity});
			this.dgvContents.Location = new System.Drawing.Point(4, 54);
			this.dgvContents.Name = "dgvContents";
			this.dgvContents.Size = new System.Drawing.Size(544, 263);
			this.dgvContents.TabIndex = 3;
			// 
			// colState
			// 
			this.colState.HeaderText = "State";
			this.colState.Name = "colState";
			// 
			// colResourceType
			// 
			this.colResourceType.HeaderText = "Type";
			this.colResourceType.Name = "colResourceType";
			this.colResourceType.Width = 300;
			// 
			// colQuantity
			// 
			this.colQuantity.HeaderText = "Quantity";
			this.colQuantity.Name = "colQuantity";
			// 
			// cmbState
			// 
			this.cmbState.FormattingEnabled = true;
			this.cmbState.Location = new System.Drawing.Point(46, 102);
			this.cmbState.Name = "cmbState";
			this.cmbState.Size = new System.Drawing.Size(101, 21);
			this.cmbState.TabIndex = 4;
			this.cmbState.Visible = false;
			// 
			// cmbType
			// 
			this.cmbType.FormattingEnabled = true;
			this.cmbType.Location = new System.Drawing.Point(148, 102);
			this.cmbType.Name = "cmbType";
			this.cmbType.Size = new System.Drawing.Size(297, 21);
			this.cmbType.TabIndex = 5;
			this.cmbType.Visible = false;
			// 
			// ntxtQuantity
			// 
			this.ntxtQuantity.BackColor = System.Drawing.Color.White;
			this.ntxtQuantity.Background_Dull = System.Drawing.Color.White;
			this.ntxtQuantity.Background_Highlight = System.Drawing.Color.Yellow;
			this.ntxtQuantity.ForeColor = System.Drawing.Color.Black;
			this.ntxtQuantity.Foreground_Dull = System.Drawing.Color.Black;
			this.ntxtQuantity.Foreground_Highlight = System.Drawing.Color.Black;
			this.ntxtQuantity.Location = new System.Drawing.Point(446, 103);
			this.ntxtQuantity.Max = 1.8446744073709552E+19D;
			this.ntxtQuantity.Min = -1.8446744073709552E+19D;
			this.ntxtQuantity.Name = "ntxtQuantity";
			this.ntxtQuantity.Size = new System.Drawing.Size(100, 20);
			this.ntxtQuantity.TabIndex = 6;
			this.ntxtQuantity.Text = "0";
			this.ntxtQuantity.Value = 0D;
			this.ntxtQuantity.Visible = false;
			// 
			// lblCapacity_Chemical
			// 
			this.lblCapacity_Chemical.AutoSize = true;
			this.lblCapacity_Chemical.Location = new System.Drawing.Point(225, 28);
			this.lblCapacity_Chemical.Name = "lblCapacity_Chemical";
			this.lblCapacity_Chemical.Size = new System.Drawing.Size(96, 13);
			this.lblCapacity_Chemical.TabIndex = 8;
			this.lblCapacity_Chemical.Text = "Chemical capacity ";
			// 
			// ntxtCapacity_Chemical
			// 
			this.ntxtCapacity_Chemical.BackColor = System.Drawing.Color.White;
			this.ntxtCapacity_Chemical.Background_Dull = System.Drawing.Color.White;
			this.ntxtCapacity_Chemical.Background_Highlight = System.Drawing.Color.Yellow;
			this.ntxtCapacity_Chemical.ForeColor = System.Drawing.Color.Black;
			this.ntxtCapacity_Chemical.Foreground_Dull = System.Drawing.Color.Black;
			this.ntxtCapacity_Chemical.Foreground_Highlight = System.Drawing.Color.Black;
			this.ntxtCapacity_Chemical.Location = new System.Drawing.Point(322, 25);
			this.ntxtCapacity_Chemical.Max = 1.8446744073709552E+19D;
			this.ntxtCapacity_Chemical.Min = 0D;
			this.ntxtCapacity_Chemical.Name = "ntxtCapacity_Chemical";
			this.ntxtCapacity_Chemical.Size = new System.Drawing.Size(100, 20);
			this.ntxtCapacity_Chemical.TabIndex = 7;
			this.ntxtCapacity_Chemical.Text = "0";
			this.ntxtCapacity_Chemical.Value = 0D;
			// 
			// btnOk
			// 
			this.btnOk.AutoSize = true;
			this.btnOk.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
			this.btnOk.Location = new System.Drawing.Point(517, 323);
			this.btnOk.Name = "btnOk";
			this.btnOk.Size = new System.Drawing.Size(31, 23);
			this.btnOk.TabIndex = 9;
			this.btnOk.Text = "Ok";
			this.btnOk.UseVisualStyleBackColor = true;
			this.btnOk.Click += new System.EventHandler(this.btnOk_Click);
			// 
			// btnResource_Add
			// 
			this.btnResource_Add.AutoSize = true;
			this.btnResource_Add.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
			this.btnResource_Add.Location = new System.Drawing.Point(329, 323);
			this.btnResource_Add.Name = "btnResource_Add";
			this.btnResource_Add.Size = new System.Drawing.Size(88, 23);
			this.btnResource_Add.TabIndex = 10;
			this.btnResource_Add.Text = "New Resource";
			this.btnResource_Add.UseVisualStyleBackColor = true;
			this.btnResource_Add.Click += new System.EventHandler(this.btnResource_Add_Click);
			// 
			// btnResource_Delete
			// 
			this.btnResource_Delete.AutoSize = true;
			this.btnResource_Delete.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
			this.btnResource_Delete.Location = new System.Drawing.Point(419, 323);
			this.btnResource_Delete.Name = "btnResource_Delete";
			this.btnResource_Delete.Size = new System.Drawing.Size(97, 23);
			this.btnResource_Delete.TabIndex = 11;
			this.btnResource_Delete.Text = "Delete Resource";
			this.btnResource_Delete.UseVisualStyleBackColor = true;
			this.btnResource_Delete.Click += new System.EventHandler(this.btnResource_Delete_Click);
			// 
			// formEditContainer
			// 
			this.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
			this.ClientSize = new System.Drawing.Size(552, 347);
			this.Controls.Add(this.btnResource_Delete);
			this.Controls.Add(this.btnResource_Add);
			this.Controls.Add(this.btnOk);
			this.Controls.Add(this.lblCapacity_Chemical);
			this.Controls.Add(this.ntxtCapacity_Chemical);
			this.Controls.Add(this.ntxtQuantity);
			this.Controls.Add(this.cmbType);
			this.Controls.Add(this.cmbState);
			this.Controls.Add(this.dgvContents);
			this.Controls.Add(this.lblCapacity_Energy);
			this.Controls.Add(this.lblResourceType);
			this.Controls.Add(this.ntxtCapacity_Energy);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
			this.Name = "formEditContainer";
			this.Text = "Container Contents Editor";
			((System.ComponentModel.ISupportInitialize)(this.dgvContents)).EndInit();
			this.ResumeLayout(false);
			this.PerformLayout();

		}
		public formEditContainer()
		{
			InitializeComponent();
			lcChemicals = classChemical.ChemicalList;
			
			cmbState.Items.Clear();
			for (enuResource_State eResState = (enuResource_State)0; eResState < enuResource_State._numResource_State; eResState++)
				cmbState.Items.Add(eResState);

			cmbState.SelectedIndexChanged += new EventHandler(cmbState_SelectedIndexChanged);
			cmbType.SelectedIndexChanged += new EventHandler(cmbType_SelectedIndexChanged);
			ntxtQuantity.EnterValue += new EventHandler<EventArgs>(ntxtQuantity_EnterValue);
			dgvContents.CellClick += new DataGridViewCellEventHandler(dgvContents_CellClick);
		}

		void ntxtQuantity_EnterValue(object sender, EventArgs e)
		{
			dgvSelectedRow.Cells[2].Value = ntxtQuantity.Value.ToString();
			ntxtQuantity.Visible = false;
		}

		void cmbType_SelectedIndexChanged(object sender, EventArgs e)
		{
			switch(classResource.getStateFromString( dgvSelectedRow.Cells[0].Value.ToString()))
			{
				case enuResource_State.chemical:
					dgvSelectedRow.Cells[1].Value = lcChemicals[cmbType.SelectedIndex].Formula;
					break;

				case enuResource_State.energy:
					dgvSelectedRow.Cells[1].Value = ((enuEnergy)cmbType.SelectedIndex).ToString();
					break;

				case enuResource_State.solid:
					dgvSelectedRow.Cells[1].Value = ((enuResources)cmbType.SelectedIndex).ToString();
					break;
			}
			cmbType.Visible = false;
		}

		void cmbState_SelectedIndexChanged(object sender, EventArgs e)
		{	
			enuResource_State eCurrentState = dgvSelectedRow.Cells[0].Value != null
														? classResource.getStateFromString( dgvSelectedRow.Cells[0].Value.ToString())
														: enuResource_State._numResource_State;
			enuResource_State eNewState = (enuResource_State)cmbState.SelectedIndex;
			if (eCurrentState != eNewState)
			{
				dgvSelectedRow.Cells[0].Value = eNewState.ToString();
				setCmbType(eNewState);
			}
		}

		void setCmbType(enuResource_State eNewState)
		{
			cmbType.Items.Clear();
			switch (eNewState)
			{
				case enuResource_State.chemical:
					for (int intChemicalCounter = 0; intChemicalCounter < lcChemicals.Count; intChemicalCounter++)
					{
						cmbType.Items.Add(lcChemicals[intChemicalCounter].Formula);
					}
					break;

				case enuResource_State.energy:
					for (enuEnergy eEnergyCounter = (enuEnergy)0; eEnergyCounter < enuEnergy._numEnergy; eEnergyCounter++)
						cmbType.Items.Add(eEnergyCounter.ToString());
					break;

				case enuResource_State.solid:
					for (enuResources eResourceCounter = (enuResources)0; eResourceCounter < enuResources._numResources; eResourceCounter++)
						cmbType.Items.Add(eResourceCounter);
					break;
			}
		}

		void dgvContents_CellClick(object sender, DataGridViewCellEventArgs e)
		{
			if (e.RowIndex >= 0 && e.RowIndex < dgvContents.Rows.Count)
			{
				dgvSelectedRow = dgvContents.Rows[e.RowIndex];
				switch (e.ColumnIndex)
				{
					case 0:
						cmbState.Visible = true;
						break;

					case 1:
						cmbType.Visible = true;
						break;

					case 2:
						ntxtQuantity.Visible = (dgvSelectedRow.Cells[0].Value != null
												&& classResource.getStateFromString(dgvSelectedRow.Cells[0].Value.ToString()) != enuResource_State.solid);
						ntxtQuantity.Value = Convert.ToDouble(dgvSelectedRow.Cells[2].Value);
						ntxtQuantity.Focus();
						break;
				}
				cmbState.Top
					= cmbType.Top
					= ntxtQuantity.Top 
					= dgvSelectedRow.Height * e.RowIndex + dgvContents.Top + 22;
			}
		}

		private DataGridViewTextBoxColumn colState;
		private DataGridViewTextBoxColumn colResourceType;
		private DataGridViewTextBoxColumn colQuantity;
		private ComboBox cmbState;
		private ComboBox cmbType;
		private CK_Controls.TextBox_Numeric ntxtQuantity;
		private Label lblCapacity_Chemical;
		private CK_Controls.TextBox_Numeric ntxtCapacity_Chemical;
		private Button btnOk;

		private void btnOk_Click(object sender, EventArgs e)
		{
			cResObject.cChemicalInventory.Capacity = (ulong)Math.Ceiling(ntxtCapacity_Chemical.Value);
			for (enuEnergy eEnergyCounter = (enuEnergy)0; eEnergyCounter < enuEnergy._numEnergy; eEnergyCounter++)
				cResObject.cEnergyInventory.setCapacity(eEnergyCounter, (long)Math.Ceiling(ntxtCapacity_Energy.Value));
			cResObject.cObjContainer.lcResourceObjects.Clear();
			for (int intRowCounter = 0; intRowCounter < dgvContents.Rows.Count-1; intRowCounter++)
			{
				DataGridViewRow dgvThisRow = dgvContents.Rows[intRowCounter];
				enuResource_State eState = classResource.getStateFromString(dgvThisRow.Cells[0].Value.ToString());
				switch (eState)
				{
					case enuResource_State.chemical:
						cResObject.cChemicalInventory.setChemicalInventory(dgvThisRow.Cells[1].Value.ToString(), Convert.ToInt64(dgvThisRow.Cells[2].Value));
						break;

					case enuResource_State.energy:
						cResObject.cEnergyInventory.setEnergy(dgvThisRow.Cells[1].Value.ToString(), Convert.ToInt64(dgvThisRow.Cells[2].Value));
						break;

					case enuResource_State.solid:
						classResourceObject cNewContent = new classResourceObject();
						cNewContent.eResource = classResource.getResourceFromString(dgvThisRow.Cells[1].Value.ToString());
						cResObject.cObjContainer.addResource_Object(ref cNewContent);
						break;
				}
			}
			Dispose();
		}

		private Button btnResource_Add;
		private Button btnResource_Delete;

		private void btnResource_Add_Click(object sender, EventArgs e)
		{
			dgvContents.Rows.Add();
			initNewRow();
		}

		void initNewRow()
		{
			if (dgvContents.Rows.Count > 1)
			{
				DataGridViewRow dgvNewRow = dgvContents.Rows[dgvContents.Rows.Count - 2];
				dgvNewRow.Cells[0].Value = enuResource_State.solid.ToString();
				dgvNewRow.Cells[1].Value = enuResources.Chair.ToString();
				dgvNewRow.Cells[2].Value = "1";
			}
		}

		private void btnResource_Delete_Click(object sender, EventArgs e)
		{
			if (dgvSelectedRow != null)
				try
				{
					dgvContents.Rows.Remove(dgvSelectedRow);
				}
				catch (Exception)
				{ }
		}
	}

	public partial class formStructureInteriorEditor : Form
	{
		static int intUniqueIDCounter = 0;
		int intMyUniqueID = intUniqueIDCounter++;
		enum enuMode_StructureInteriorEditor { edit_Structure, edit_Teleporters, edit_Resources, edit_Astronauts, edit_Ships, Move };
		enum enuTelePortEdit_PointSelection { Pos, RadArrivingObject, Radius, RealWorldHeight };

		enuTelePortEdit_PointSelection eTelePortEdit_PointSelection = enuTelePortEdit_PointSelection.Pos;
		enuTelePortEdit_PointSelection eTelePortEdit_PointSelection_Next = enuTelePortEdit_PointSelection.Pos;
		public static formStructureInteriorEditor frmStructureInteriorEditor_Current = null;
		public static formStructureInteriorEditor frmStructureInteriorEditor_Main = null; 
		enuMode_StructureInteriorEditor _eMode = enuMode_StructureInteriorEditor.edit_Structure;

		public static bool bolChangesMadeSinceLastSave = false;

		enuMode_StructureInteriorEditor eMode
		{
			get { return _eMode; }
			set
			{
				if (value == _eMode) return;
				if (_eMode == enuMode_StructureInteriorEditor.Move)
				{
					classGameState.cControlAstronaut = null;
					classGameState.cControlAstronaut_Next = null;
				}
				if (value == enuMode_StructureInteriorEditor.Move)
				{
					if (classGameState.cControlAstronaut == null)
					{
						classGameState.cControlAstronaut = cSI_Room.getNearestAstronaut(new classMath.classDoubleCartesian());
					}
					if (classGameState.cControlAstronaut == null)
					{
						eMode = enuMode_StructureInteriorEditor.edit_Astronauts;
						return;
					}
					classGameState.cTrackObject = classGameState.cControlAstronaut.cCDO;
				}
				else
				{
					classGameState.cTrackObject = null;
				}

				if (_eMode == enuMode_StructureInteriorEditor.Move && value != enuMode_StructureInteriorEditor.Move)
				{
					gtmrGame.stop();
					if (cmbRooms.SelectedIndex < 0) cmbRooms.SelectedIndex = 0;
					cSI_Room = cSI.cRooms[cmbRooms.SelectedIndex];
				}

				_eMode = value;
				intIndexPoint_NextSelect = -1;
				intIndexPoint_Selected = -1;
				bolShipEdit_Rotate = false;

				switch (eMode)
				{
					case enuMode_StructureInteriorEditor.Move:
						if (classGameState.cControlAstronaut == null) classGameState.cControlAstronaut = classAstronaut.cAstronauts[0];
						classGameState.dptViewFocus = classGameState.cControlAstronaut.cCDO.dptPos.Copy();
						gtmrGame.start();
						break;

					default:
						if (classGameState.dptViewFocus == null)
							classGameState.dptViewFocus = new classMath.classDoubleCartesian();
						break;
				}
				cmbRooms.Visible
					= cmbLocation.Visible
					= (_eMode != enuMode_StructureInteriorEditor.Move);
				drawScreen();
				this.Focus();
			}
		}
		classSolarObject cEarth;
		string strWorkingDirectory = formMarsMission.strWorkingDirectory;
		bool[] bolMouseDown = new bool[3];
		classMath.classDoubleCartesian dptMouse = new classMath.classDoubleCartesian();
		Point ptMouse;
		classStructureInterior cSI = new classStructureInterior();

		public static Label lblDebug;

		ContextMenu cmnu = new ContextMenu();
		enum enuMode { idle, MovePoint };
		int intIndexPoint_Selected = -1;
		int intIndexPoint_NextSelect = -1;
		int intPolygon_Selected = -1;
		int intPolygon_NextSelected = -1;
		int intTeleporter_Selected = -1;
		int intTeleporter_NextSelected = -1;
		int intShip_Selected = -1;
		int intShip_NextSelected = -1;

		Pen pBold = classPensAndBrushes.pBlack2;
		Pen pDull = classPensAndBrushes.pLightGray2;
		Pen pHighlight = classPensAndBrushes.pRed2;

		int intCircleRadius = 5;

		CK_Controls.Timer_Game gtmrGame = new CK_Controls.Timer_Game();

		public static Font fntText = new Font("ms sans-serif", 8);

		MenuItem mnuItem_Point;
		MenuItem mnuItem_Point_Add;
		MenuItem mnuItem_Point_Add_Before;
		MenuItem mnuItem_Point_Add_After;
		MenuItem mnuItem_Point_Delete;

		MenuItem mnuItem_Polygon;
		MenuItem mnuItem_Polygon_Add;
		MenuItem mnuItem_Polygon_Delete;

		MenuItem mnuItem_Room;
		MenuItem mnuItem_Room_Add;
		MenuItem mnuItem_Room_Delete;
		MenuItem mnuItem_Room_EditName;

		MenuItem mnuItem_Astronaut;
		MenuItem mnuItem_Astronaut_Add;
		MenuItem mnuItem_Astronaut_Delete;
		MenuItem mnuItem_Astronaut_Edit;

		MenuItem mnuItem_Ship;
		MenuItem mnuItem_Ship_Add;
		MenuItem mnuItem_Ship_Delete;
		MenuItem mnuItem_Ship_EditName;
		MenuItem mnuItem_Ship_EditStructure;
		MenuItem mnuItem_Ship_Rotate;

		MenuItem mnuItem_Resource;
		MenuItem mnuItem_Resource_Add;
		MenuItem mnuItem_Resource_Delete;
		MenuItem mnuItem_Resource_EditContainer;
		MenuItem mnuItem_Resource_Mirror;
		MenuItem mnuItem_Resource_Mirror_none;
		MenuItem mnuItem_Resource_Mirror_vertical;
		MenuItem mnuItem_Resource_Mirror_horizontal;
		MenuItem mnuItem_Resource_Mirror_both;

		MenuItem mnuItem_Mode_Move_TestCollisionDetection;
		MenuItem mnuItem_Mode_Edit_Structure;
		MenuItem mnuItem_Mode_EditTeleporters;
		MenuItem mnuItem_Mode_EditResources;
		MenuItem mnuItem_Mode_EditAstronauts;
		MenuItem mnuItem_Mode_EditShips;

		MenuItem mnuItem_Mode;

		MenuItem mnuItem_Teleporters_ShowPage;

		MenuItem mnuItem_ClearDebugXml;

		MenuItem mnuItem_Toggles;
		MenuItem mnuItem_ToggleMouseMove;
		MenuItem mnuItem_ToggleViewCDP;
		MenuItem mnuItem_ToggleViewSprite;
		MenuItem mnuItem_ToggleViewTeleporter;
		MenuItem mnuItem_ToggleShowZoomBar;

		MenuItem mnuShowAvailableActions;

		public classMath.classDoubleCartesian dptGrab;
		PictureBox _picView = null;

		classCollisionDetectionObject[] cDebugCDO = new classCollisionDetectionObject[0];
		classStructureInterior_Room cSI_Room;
		string strLoadDefault = formMarsMission.strWorkingDirectory + "structureInterior_default.xml";
		public formStructureInteriorEditor(params string[] strCommandLine)
		{
			if (strCommandLine != null && strCommandLine.Length > 0)
				strLoadDefault = strCommandLine[0];
			initialize();
			TextChanged += new EventHandler(formStructureInteriorEditor_TextChanged);
			
		}

		void formStructureInteriorEditor_TextChanged(object sender, EventArgs e)
		{
			
		}

		void picView_SizeChanged(object sender, EventArgs e)
		{
			if (classGameState.g != null) classGameState.g.Dispose();
			if (classGameState.picView.Width < 10 || classGameState.picView.Height < 10) return;
			classGameState.bmpViewScreen = new Bitmap(classGameState.picView.Width, classGameState.picView.Height);
			classGameState.g = Graphics.FromImage(classGameState.bmpViewScreen);

		}

		public formStructureInteriorEditor(ref classStructureInterior SI)
		{
			strLoadDefault = "";
			cSI = SI;
			initialize();
		}
		static bool bolInit = false;

		void buildPicView()
		{
			if (_picView != null)
			{
				_picView.Visible = false;
				_picView.Dispose();
			}
			_picView = new PictureBox();
			classGameState.picView = _picView;
			classGameState.picView.Dock = DockStyle.Fill; 
			Controls.Add(classGameState.picView);
			classGameState.picView.MouseMove += new MouseEventHandler(picView_MouseMove);
			classGameState.picView.MouseDown += new MouseEventHandler(picView_MouseDown);
			classGameState.picView.MouseUp += new MouseEventHandler(picView_MouseUp);
			classGameState.picView.MouseWheel += new MouseEventHandler(formStructureInteriorEditor_MouseWheel);
			classGameState.picView.SizeChanged += new EventHandler(picView_SizeChanged);
			classGameState.picView.ContextMenu = cmnu;
			cmnu.Popup += new EventHandler(cmnu_Popup);
			classGameState.picView.SendToBack();
		}

		private void initialize()
		{
			if (frmStructureInteriorEditor_Main == null) frmStructureInteriorEditor_Main = this;

			Controls.Add(lblZoom);
			Controls.Add(hsbZoom);
			Controls.Add(cmbLocation);
			Controls.Add(cmbRooms);
			
			buildPicView();
						
			frmStructureInteriorEditor_Current = this;
			Icon = Properties.Resources.Mars_Mission___icon;
			InitializeComponent();
			
			classGameState.dptViewFocus = new classMath.classDoubleCartesian();
			if (!bolInit)
			{
				lblDebug = new Label();
				Controls.Add(lblDebug); lblDebug.AutoSize = true; lblDebug.SizeChanged += new EventHandler(lblDebug_SizeChanged);

				classResourceXML.loadXml();
				classActionXML.loadXml();

				classResource.loadResources();
				classAction.loadActions();
				classChemistry.Load();
				classSolarObject.cSolarObjects = classSolarObjectsXml.getSolarObjects();
				bolInit = true;
			}
			gtmrGame.Interval = 100;
			gtmrGame.Tick += new EventHandler<EventArgs>(gtmrGame_Tick);

			cEarth = classSolarObject.cSolarObjects[(int)enuSolarObjects.Earth];
			
			classGameState.setZoom(1.0);
			classGameState.cTrackObject = new classCollisionDetectionObject();

			mnuItem_Point = new MenuItem("Point");
			mnuItem_Point_Add = new MenuItem("add point");
			mnuItem_Point_Delete = new MenuItem("delete point", Point_Delete);
			mnuItem_Point_Add_After = new MenuItem("After", Point_Add_After);
			mnuItem_Point_Add.MenuItems.Add(mnuItem_Point_Add_After);
			mnuItem_Point_Add_Before = new MenuItem("Before", Point_Add_Before);
			mnuItem_Point_Add.MenuItems.Add(mnuItem_Point_Add_Before);

			mnuItem_Point.MenuItems.Add(mnuItem_Point_Add);
			mnuItem_Point.MenuItems.Add(mnuItem_Point_Delete);

			mnuItem_Polygon = new MenuItem("Polygon");
			mnuItem_Polygon_Add = new MenuItem("Add Polygon", Polygon_Add);
			mnuItem_Polygon_Delete = new MenuItem("Delete Polygon", Polygon_Delete);
			mnuItem_Polygon.MenuItems.Add(mnuItem_Polygon_Add);
			mnuItem_Polygon.MenuItems.Add(mnuItem_Polygon_Delete);

			mnuItem_Room = new MenuItem("Room");
			mnuItem_Room_Add = new MenuItem("Add Room", Room_Add);
			mnuItem_Room_Delete = new MenuItem("Delete Room", Room_Delete);
			mnuItem_Room_EditName = new MenuItem("Edit Name", Room_EditName);
			mnuItem_Room.MenuItems.Add(mnuItem_Room_Add);
			mnuItem_Room.MenuItems.Add(mnuItem_Room_Delete);
			mnuItem_Room.MenuItems.Add(mnuItem_Room_EditName);

			mnuItem_Astronaut = new MenuItem("Astronaut");
			mnuItem_Astronaut_Add = new MenuItem("Add Astronaut", Astronaut_Add);
			mnuItem_Astronaut_Delete = new MenuItem("Delete Astronaut", Astronaut_Delete);
			mnuItem_Astronaut_Edit = new MenuItem("Edit Name", Astronaut_Edit);
			mnuItem_Astronaut.MenuItems.Add(mnuItem_Astronaut_Add);
			mnuItem_Astronaut.MenuItems.Add(mnuItem_Astronaut_Delete);
			mnuItem_Astronaut.MenuItems.Add(mnuItem_Astronaut_Edit);

			mnuItem_Ship = new MenuItem("Ship");
			mnuItem_Ship_Add = new MenuItem("Add Ship", Ship_Add);
			mnuItem_Ship_Delete = new MenuItem("Delete Ship", Ship_Delete);
			mnuItem_Ship_EditName = new MenuItem("Edit Name", Ship_EditName);
			mnuItem_Ship_EditStructure = new MenuItem("Edit Structure", Ship_EditStructure);
			mnuItem_Ship_Rotate = new MenuItem("rotate", Ship_Rotate);
			mnuItem_Ship.MenuItems.Add(mnuItem_Ship_Add);
			mnuItem_Ship.MenuItems.Add(mnuItem_Ship_Delete);
			mnuItem_Ship.MenuItems.Add(mnuItem_Ship_EditName);
			mnuItem_Ship.MenuItems.Add(mnuItem_Ship_EditStructure);
			mnuItem_Ship.MenuItems.Add(mnuItem_Ship_Rotate);

			mnuItem_Resource = new MenuItem("Resource");
			mnuItem_Resource_Add = new MenuItem("Add Resource", Resource_Add);
			mnuItem_Resource_Delete = new MenuItem("Delete Resource", Resource_Delete);
			mnuItem_Resource_EditContainer = new MenuItem("Edit Container", Resource_EditContainer);
			mnuItem_Resource.MenuItems.Add(mnuItem_Resource_Add);
			mnuItem_Resource.MenuItems.Add(mnuItem_Resource_Delete);
			mnuItem_Resource.MenuItems.Add(mnuItem_Resource_EditContainer);
			mnuItem_Resource_Mirror = new MenuItem("Mirror");
			mnuItem_Resource_Mirror_none = new MenuItem("none", ResourceMirror_none);
			mnuItem_Resource_Mirror.MenuItems.Add(mnuItem_Resource_Mirror_none);
			mnuItem_Resource_Mirror_vertical = new MenuItem("vertical", ResourceMirror_vertical);
			mnuItem_Resource_Mirror.MenuItems.Add(mnuItem_Resource_Mirror_vertical);
			mnuItem_Resource_Mirror_horizontal = new MenuItem("horizontal", ResourceMirror_horizontal);
			mnuItem_Resource_Mirror.MenuItems.Add(mnuItem_Resource_Mirror_horizontal);
			mnuItem_Resource_Mirror_both = new MenuItem("both", ResourceMirror_both);
			mnuItem_Resource_Mirror.MenuItems.Add(mnuItem_Resource_Mirror_both);
			mnuItem_Resource.MenuItems.Add(mnuItem_Resource_Mirror);

			mnuItem_Mode_Move_TestCollisionDetection = new MenuItem("Move - test collision detection", Move_TestCollisionDetection);
			mnuItem_Mode_Edit_Structure = new MenuItem("Edit Structure", Edit_Structure);
			mnuItem_Mode_EditTeleporters = new MenuItem("Edit Teleporters", Edit_Teleporters);
			mnuItem_Mode_EditResources = new MenuItem("Edit Resources", Edit_Resources);
			mnuItem_Mode_EditAstronauts = new MenuItem("Edit Astronauts", Edit_Astronauts);
			mnuItem_Mode_EditShips = new MenuItem("Edit Ships", Edit_Ships);

			mnuItem_Teleporters_ShowPage = new MenuItem("Show Teleporter Page", ShowTeleporterPage);

			mnuItem_Mode = new MenuItem("Mode");
			mnuItem_Mode.MenuItems.Add(mnuItem_Mode_Edit_Structure);
			mnuItem_Mode.MenuItems.Add(mnuItem_Mode_EditTeleporters);
			mnuItem_Mode.MenuItems.Add(mnuItem_Mode_EditResources);
			mnuItem_Mode.MenuItems.Add(mnuItem_Mode_EditAstronauts);
			mnuItem_Mode.MenuItems.Add(mnuItem_Mode_EditShips);
			mnuItem_Mode.MenuItems.Add(mnuItem_Mode_Move_TestCollisionDetection);

			mnuItem_Toggles = new MenuItem("Toggles");
			mnuItem_ToggleMouseMove = new MenuItem("Toggle Mouse move", ToggleMouseMove);
			mnuItem_ToggleViewCDP = new MenuItem("CDP visible", ToggleCDPVisible);
			mnuItem_ToggleViewSprite = new MenuItem("Sprite visible", ToggleSpriteVisible);
			mnuItem_ToggleViewTeleporter = new MenuItem("Teleporters visible", ToggleVewTeleporters);
			mnuItem_ToggleShowZoomBar = new MenuItem("Show Zoom Bar", mnuOptions_ShowZoomBar_Click);
			mnuItem_Toggles.MenuItems.Add(mnuItem_ToggleViewCDP);
			mnuItem_Toggles.MenuItems.Add(mnuItem_ToggleViewSprite);
			mnuItem_Toggles.MenuItems.Add(mnuItem_ToggleViewTeleporter);
			mnuItem_Toggles.MenuItems.Add(mnuItem_ToggleMouseMove);
			mnuItem_Toggles.MenuItems.Add(mnuItem_ToggleShowZoomBar);

			mnuShowAvailableActions = new MenuItem("Show Available Actions", ShowAvailableActions);

			mnuItem_ClearDebugXml = new MenuItem("clear Debug", ClearDebugXml);

			hsbZoom.Minimum = 3;
			hsbZoom.Maximum = 65;
			hsbZoom.LargeChange = 4;

			KeyDown += new KeyEventHandler(_keyDown);
			cmbRooms.KeyDown += new KeyEventHandler(_keyDown);
			hsbZoom.KeyDown += new KeyEventHandler(_keyDown);

			KeyUp += new KeyEventHandler(_keyUp);
			cmbRooms.KeyUp += new KeyEventHandler(_keyUp);
			hsbZoom.KeyUp += new KeyEventHandler(_keyUp);

			SizeChanged += new EventHandler(formStructureInteriorEditor_SizeChanged);

			MouseWheel += new MouseEventHandler(formStructureInteriorEditor_MouseWheel);
			
			hsbZoom.ValueChanged += new EventHandler(hsbZoom_ValueChanged);

			VisibleChanged += new EventHandler(formStructureInteriorEditor_VisibleChanged);

			cmbRooms.SelectedIndexChanged += new EventHandler(cmbRooms_SelectedIndexChanged);
			cmbLocation.Items.Clear();
			cmbLocation.Items.Add(enuLocation.Ship.ToString());
			cmbLocation.Items.Add(enuLocation.Building.ToString());

			cmbLocation.SelectedIndexChanged += new EventHandler(cmbLocation_SelectedIndexChanged);
			cmbLocation.SelectedIndex = 0;
			if (formMarsMission.frmActionSchedule == null)
			{
				formMarsMission.initFormActionSchedule();
			}
		}

		void formStructureInteriorEditor_VisibleChanged(object sender, EventArgs e)
		{
			if (Visible)
			{
				Width = Screen.PrimaryScreen.WorkingArea.Width;
				Height = Screen.PrimaryScreen.WorkingArea.Height;
				Location = new Point(0, 0);
				if (strLoadDefault.Length > 0)
					cSI = classStructureInterior.fromXmlFile(strLoadDefault);

				cSI_Room = cSI.cRooms[0];
				cmbLocation.SelectedIndex = (cSI.eLoc == enuLocation.Ship ? 0 : 1);

				rebuildCmbRooms();
				drawScreen();
				eMode = enuMode_StructureInteriorEditor.edit_Structure;
				hsbZoom.Value = hsbZoom.Minimum + 2;
			}
		}

		void cmbLocation_SelectedIndexChanged(object sender, EventArgs e)
		{
			cSI.eLoc = (cmbLocation.SelectedIndex == 0) ? enuLocation.Ship : enuLocation.Building;

			foreach (classStructureInterior_Room cRoom in cSI.cRooms)
			{
				foreach (classShip cShip in cRoom.cObjContainer.lcShips)
					cShip.cCDO.eLoc = cSI.eLoc;

				foreach (classAstronaut cAstronaut in cRoom.cObjContainer.lcAstronauts)
					cAstronaut.cCDO.eLoc = cSI.eLoc;

				foreach (classResourceObject cResOb in cRoom.cObjContainer.lcResourceObjects)
					cResOb.cCDO.eLoc = cSI.eLoc;
			}
		}

		void lblDebug_SizeChanged(object sender, EventArgs e)
		{
			lblDebug.Location = new Point(Width - 25 - lblDebug.Width, Height - lblDebug.Height - 45);
			lblDebug.BringToFront();
		}

		bool bolIgnoreChangesToCmbRooms = false;
		void cmbRooms_SelectedIndexChanged(object sender, EventArgs e)
		{
			if (bolIgnoreChangesToCmbRooms || eMode == enuMode_StructureInteriorEditor.Move) return;
			cSI_Room = cSI.cRooms[cmbRooms.SelectedIndex];
			intPolygon_NextSelected
				= intPolygon_Selected
				= intIndexPoint_NextSelect
				= intIndexPoint_Selected
				= intTeleporter_NextSelected
				= intTeleporter_Selected
				= intShip_Selected
				= intShip_NextSelected
				= -1;
			drawScreen();
		}

		void rebuildCmbRooms()
		{
			bolIgnoreChangesToCmbRooms = true;
			cmbRooms.Items.Clear();

			for (int intRoomCounter = 0; intRoomCounter < cSI.cRooms.Length; intRoomCounter++)
				cmbRooms.Items.Add(cSI.cRooms[intRoomCounter].Name);
			if (cSI_Room.intIndex >= cSI.cRooms.Length)
				cSI_Room = cSI.cRooms[cSI.cRooms.Length - 1];

			cmbRooms.SelectedIndex = cSI_Room.intIndex;
			if (cmbRooms.SelectedIndex < 0)
				cmbRooms.SelectedIndex = 0;
			cmbRooms.Text = cmbRooms.Items[cmbRooms.SelectedIndex].ToString();
			bolIgnoreChangesToCmbRooms = false;
		}

		void ResourceMirror_none(object sender, EventArgs e)
		{
			if (intIndexPoint_Selected >= 0 && intIndexPoint_Selected < cSI_Room.cObjContainer.lcResourceObjects.Count)
			{
				cSI_Room.cObjContainer.lcResourceObjects[intIndexPoint_Selected].cCDO.cCDP.eMirror = Sprite.enuMirror.none;
				drawScreen();
			}
		}

		void ResourceMirror_both(object sender, EventArgs e)
		{
			if (intIndexPoint_Selected >= 0 && intIndexPoint_Selected < cSI_Room.cObjContainer.lcResourceObjects.Count)
			{
				cSI_Room.cObjContainer.lcResourceObjects[intIndexPoint_Selected].cCDO.cCDP.eMirror = Sprite.enuMirror.VerticalAndHorizontal;
				drawScreen();
			}
		}

		void ResourceMirror_horizontal(object sender, EventArgs e)
		{
			if (intIndexPoint_Selected >= 0 && intIndexPoint_Selected < cSI_Room.cObjContainer.lcResourceObjects.Count)
			{
				cSI_Room.cObjContainer.lcResourceObjects[intIndexPoint_Selected].cCDO.cCDP.eMirror = Sprite.enuMirror.horizontal;
				drawScreen();
			}
		}

		void ResourceMirror_vertical(object sender, EventArgs e)
		{
			if (intIndexPoint_Selected >= 0 && intIndexPoint_Selected < cSI_Room.cObjContainer.lcResourceObjects.Count)
			{
				cSI_Room.cObjContainer.lcResourceObjects[intIndexPoint_Selected].cCDO.cCDP.eMirror = Sprite.enuMirror.vertical;
				drawScreen();
			}
		}

		void _keyUp(object sender, KeyEventArgs e)
		{
			if (classGameState.cControlAstronaut == null) return;
			if (classGameState.cControlAstronaut.bolAstronautControlKeys == null)
				classGameState.cControlAstronaut.bolAstronautControlKeys = new bool[(int)enuAstronautControlKeys._numMoveKey];
			switch (e.KeyCode)
			{
				case Keys.S:
					classGameState.cControlAstronaut.bolAstronautControlKeys[(int)enuAstronautControlKeys.left] = false;
					break;

				case Keys.F:
					classGameState.cControlAstronaut.bolAstronautControlKeys[(int)enuAstronautControlKeys.right] = false;
					break;

				case Keys.E:
					classGameState.cControlAstronaut.bolAstronautControlKeys[(int)enuAstronautControlKeys.up] = false;
					break;

				case Keys.C:
					classGameState.cControlAstronaut.bolAstronautControlKeys[(int)enuAstronautControlKeys.down] = false;
					break;

				case Keys.D:
					classGameState.cControlAstronaut.bolAstronautControlKeys[(int)enuAstronautControlKeys.turn] = false;
					break;

				case Keys.R:
					classGameState.cControlAstronaut.bolAstronautControlKeys[(int)enuAstronautControlKeys.stand] = false;
					break;

				case Keys.V:
					classGameState.cControlAstronaut.bolAstronautControlKeys[(int)enuAstronautControlKeys.crouch] = false;
					break;

				case Keys.X:
					classGameState.cControlAstronaut.bolAstronautControlKeys[(int)enuAstronautControlKeys.sit] = false;
					break;

				case Keys.Enter:
					classGameState.cControlAstronaut.bolAstronautControlKeys[(int)enuAstronautControlKeys.automatedAction] = false;
					e.SuppressKeyPress = true;
					break;
			}
		}

		void _keyDown(object sender, KeyEventArgs e)
		{

			if (classGameState.cControlAstronaut == null) return;
			if (classGameState.cControlAstronaut.bolAstronautControlKeys == null)
				classGameState.cControlAstronaut.bolAstronautControlKeys = new bool[(int)enuAstronautControlKeys._numMoveKey]; switch (e.KeyCode)
			{
				case Keys.S:
					classGameState.cControlAstronaut.bolAstronautControlKeys[(int)enuAstronautControlKeys.left] = true;
					break;

				case Keys.F:
					classGameState.cControlAstronaut.bolAstronautControlKeys[(int)enuAstronautControlKeys.right] = true;
					break;

				case Keys.E:
					classGameState.cControlAstronaut.bolAstronautControlKeys[(int)enuAstronautControlKeys.up] = true;
					break;

				case Keys.C:
					classGameState.cControlAstronaut.bolAstronautControlKeys[(int)enuAstronautControlKeys.down] = true;
					break;

				case Keys.D:
					classGameState.cControlAstronaut.bolAstronautControlKeys[(int)enuAstronautControlKeys.turn] = true;
					break;

				case Keys.R:
					classGameState.cControlAstronaut.bolAstronautControlKeys[(int)enuAstronautControlKeys.stand] = true;
					break;

				case Keys.V:
					classGameState.cControlAstronaut.bolAstronautControlKeys[(int)enuAstronautControlKeys.crouch] = true;
					break;

				case Keys.X:
					classGameState.cControlAstronaut.bolAstronautControlKeys[(int)enuAstronautControlKeys.sit] = true;
					break;

				case Keys.Enter:
					classGameState.cControlAstronaut.bolAstronautControlKeys[(int)enuAstronautControlKeys.automatedAction] = true;
					e.SuppressKeyPress = true;
					break;
			}
		}

		void Edit_Teleporters(object sender, EventArgs e) { eMode = enuMode_StructureInteriorEditor.edit_Teleporters; }
		void Edit_Structure(object sender, EventArgs e) { eMode = enuMode_StructureInteriorEditor.edit_Structure; }
		void Edit_Resources(object sender, EventArgs e) { eMode = enuMode_StructureInteriorEditor.edit_Resources; }
		void Edit_Astronauts(object sender, EventArgs e) { eMode = enuMode_StructureInteriorEditor.edit_Astronauts; }
		void Edit_Ships(object sender, EventArgs e) { eMode = enuMode_StructureInteriorEditor.edit_Ships; }
		void Move_TestCollisionDetection(object sender, EventArgs e) { eMode = enuMode_StructureInteriorEditor.Move; }
		void ClearDebugXml(object sender, EventArgs e)
		{
			cDebugCDO = new classCollisionDetectionObject[0];
		}

		void ShowTeleporterPage(object sender, EventArgs e)
		{
			formTeleporterCoupling_Editor frmTeleporterCoupling_editor = new formTeleporterCoupling_Editor(ref cSI);
			frmTeleporterCoupling_editor.ShowDialog();
			cSI.resetTeleporterRooms();
			drawScreen();
		}

		bool bolViewCDP = false;
		void ToggleCDPVisible(object sender, EventArgs e)
		{
			bolViewCDP = !bolViewCDP;
			drawScreen();
		}
		bool bolViewSprite = true;
		void ToggleSpriteVisible(object sender, EventArgs e)
		{
			bolViewSprite = !bolViewSprite;
			drawScreen();
		}
		bool bolMouseControl = true;
		void ToggleMouseMove(object sender, EventArgs e)
		{
			bolMouseControl = !bolMouseControl;
		}

		bool bolView_Teleporters = false;
		void ToggleVewTeleporters(object sender, EventArgs e)
		{
			bolView_Teleporters = !bolView_Teleporters;
			drawScreen();
		}

		void gtmrGame_Tick(object sender, EventArgs e)
		{
			gtmrGame.Pause();
			classGameState.ulngTime++;
			classActionSchedule.ActionQ();
			if (classGameState.cControlAstronaut == null)
			{
				if (cSI_Room.cObjContainer.lcAstronauts.Count > 0)
				{
					classGameState.cControlAstronaut = cSI_Room.cObjContainer.lcAstronauts[0];
				}
				else
				{
					eMode = enuMode_StructureInteriorEditor.edit_Astronauts;
					return;
				}
			}
			dptMouse = classLandscape.getPointLandscape(new Point(Control.MousePosition.X - Left - classGameState.picView.Left, Control.MousePosition.Y - Top - classGameState.picView.Top), classGameState.ptScreenCenter, classGameState.cControlAstronaut.cCDO.dptPos);

			classGameState.cControlAstronaut.animate();
			cSI_Room.animateResourcesAndTeleporters();

			if (eMode == enuMode_StructureInteriorEditor.Move)
			{
				classGameState.dptViewFocus = classGameState.cControlAstronaut.cCDO.dptPos.Copy();
				drawScreen();
				gtmrGame.Restart();
			}
		}

		PointF ptfText = new PointF(10, 10);

		void hsbZoom_ValueChanged(object sender, EventArgs e)
		{
			classGameState.setZoom(hsbZoom.Value);
			showZoomLabel();
			drawScreen();
		}

		void formStructureInteriorEditor_MouseWheel(object sender, MouseEventArgs e)
		{
			double dblDeltaAngle = Math.PI / 8;

			if (formMarsMission.bolKeyState[(int)enuKeys.Zoom])
			{
				if (e.Delta > 0)
					classGameState.ZoomIn();
				else
					classGameState.ZoomOut();
				return;
			}

			switch (eMode)
			{
				case enuMode_StructureInteriorEditor.Move:
					if ((e.Delta < 0 && classGameState.cControlAstronaut.cCDO.cCDP.eMirror == Sprite.enuMirror.none)
						|| (e.Delta > 0 && classGameState.cControlAstronaut.cCDO.cCDP.eMirror == Sprite.enuMirror.horizontal))
					{
						classGameState.cControlAstronaut.RotateArm(dblDeltaAngle);
					}
					else
					{
						classGameState.cControlAstronaut.RotateArm(-dblDeltaAngle);
					}
					break;

				case enuMode_StructureInteriorEditor.edit_Resources:
					if (intIndexPoint_Selected >= 0 && intIndexPoint_Selected < cSI_Room.cObjContainer.lcResourceObjects.Count)
					{
						if (e.Delta < 0)
						{
							cSI_Room.cObjContainer.lcResourceObjects[intIndexPoint_Selected].cCDO.dblAngle = classMath.cleanAngle(cSI_Room.cObjContainer.lcResourceObjects[intIndexPoint_Selected].cCDO.dblAngle + dblDeltaAngle);
						}
						else
						{
							cSI_Room.cObjContainer.lcResourceObjects[intIndexPoint_Selected].cCDO.dblAngle = classMath.cleanAngle(cSI_Room.cObjContainer.lcResourceObjects[intIndexPoint_Selected].cCDO.dblAngle - dblDeltaAngle);
						}
						drawScreen();
					}
					break;

				case enuMode_StructureInteriorEditor.edit_Ships:
					if (bolShipEdit_Rotate)
					{
						if (intShip_Selected >= 0)
						{
							if (e.Delta < 0) dblDeltaAngle *= -1;

							cSI_Room.cObjContainer.lcShips[intShip_Selected].cCDO.dblAngle = classMath.cleanAngle(cSI_Room.cObjContainer.lcShips[intShip_Selected].cCDO.dblAngle + dblDeltaAngle);
							drawScreen();
						}
					}
					break;

				default:
					if (e.Delta < 0)
					{
						classGameState.ZoomIn();
					}
					else
					{
						classGameState.ZoomOut();
					}
					break;
			}
		}


		void cmnu_Popup(object sender, EventArgs e)
		{
			cmnu.MenuItems.Clear();
			cmnu.MenuItems.Add(mnuItem_Mode);
			switch (eMode)
			{
				case enuMode_StructureInteriorEditor.edit_Structure:
					cmnu.MenuItems.Add(mnuItem_Point);
					cmnu.MenuItems.Add(mnuItem_Polygon);
					cmnu.MenuItems.Add(mnuItem_Room);
					break;

				case enuMode_StructureInteriorEditor.Move:
					if (classGameState.cControlAstronaut.cActionEvent == null || classGameState.cControlAstronaut.cActionEvent.cAction.eAction == enuActions.idle)
						cmnu.MenuItems.Add(mnuShowAvailableActions);
					cmnu.MenuItems.Add(mnuItem_ToggleMouseMove);
					cmnu.MenuItems.Add(mnuItem_ClearDebugXml);
					break;

				case enuMode_StructureInteriorEditor.edit_Teleporters:
					cmnu.MenuItems.Add(mnuItem_Teleporters_ShowPage);
					break;

				case enuMode_StructureInteriorEditor.edit_Resources:
					cmnu.MenuItems.Add(mnuItem_Resource);
					break;

				case enuMode_StructureInteriorEditor.edit_Astronauts:
					cmnu.MenuItems.Add(mnuItem_Astronaut);
					break;

				case enuMode_StructureInteriorEditor.edit_Ships:
					cmnu.MenuItems.Add(mnuItem_Ship);
					break;
			}
			cmnu.MenuItems.Add(mnuItem_Toggles);
		}

		void ShowAvailableActions(object sender, EventArgs e)
		{
			formActionsAvailable.showAvailableActions(ref classGameState.cControlAstronaut);
		}

		void Polygon_Add(object sender, EventArgs e)
		{
			Array.Resize<classMath.classPolygon>(ref cSI_Room.cPolygons, cSI_Room.cPolygons.Length + 1);
			cSI_Room.cPolygons[cSI_Room.cPolygons.Length - 1] = new classMath.classPolygon();
			cSI_Room.cPolygons[cSI_Room.cPolygons.Length - 1].dptArray = new classMath.classDoubleCartesian[4];
			double dblStandardWidth = .21;
			cSI_Room.cPolygons[cSI_Room.cPolygons.Length - 1].dptArray[0] = new classMath.classDoubleCartesian(dptMouse.X - dblStandardWidth, dptMouse.Y - dblStandardWidth);
			cSI_Room.cPolygons[cSI_Room.cPolygons.Length - 1].dptArray[1] = new classMath.classDoubleCartesian(dptMouse.X - dblStandardWidth, dptMouse.Y + dblStandardWidth);
			cSI_Room.cPolygons[cSI_Room.cPolygons.Length - 1].dptArray[2] = new classMath.classDoubleCartesian(dptMouse.X + dblStandardWidth, dptMouse.Y + dblStandardWidth);
			cSI_Room.cPolygons[cSI_Room.cPolygons.Length - 1].dptArray[3] = new classMath.classDoubleCartesian(dptMouse.X + dblStandardWidth, dptMouse.Y - dblStandardWidth);
			cSI_Room.defineWallGrid();
			drawScreen();
		}

		void Polygon_Delete(object sender, EventArgs e)
		{
			if (intPolygon_Selected > 0)
			{
				for (int intPolygonCounter = intPolygon_Selected; intPolygonCounter < cSI_Room.cPolygons.Length - 1; intPolygonCounter++)
					cSI_Room.cPolygons[intPolygonCounter] = cSI_Room.cPolygons[intPolygonCounter + 1];
				Array.Resize<classMath.classPolygon>(ref cSI_Room.cPolygons, cSI_Room.cPolygons.Length - 1);
				drawScreen();
			}
		}

		void Resource_Add(object sender, EventArgs e)
		{
			formAddResource frmAddResource = new formAddResource();

			if (intIndexPoint_Selected >= 0 && intIndexPoint_Selected < cSI_Room.cObjContainer.lcResourceObjects.Count)
			{
				if (classResource.cResources[(int)cSI_Room.cObjContainer.lcResourceObjects[intIndexPoint_Selected].eResource].dblContainerMaxMass > 0)
				{
					frmAddResource.Text = cSI_Room.cObjContainer.lcResourceObjects[intIndexPoint_Selected].eResource.ToString() + " add resource to container inventory";
					//bolIsAContainer = true;
				}
			}
			classMath.classDoubleCartesian dptNewResource = dptMouse.Copy();

			frmAddResource.ShowDialog();
			if (frmAddResource.cResObject != null)
			{
				if (intIndexPoint_Selected >= 0 && intIndexPoint_Selected < cSI_Room.cObjContainer.lcResourceObjects.Count)
				{
					classResourceObject cResSelected = cSI_Room.cObjContainer.lcResourceObjects[intIndexPoint_Selected];

					if (classResource.cResources[(int)cSI_Room.cObjContainer.lcResourceObjects[intIndexPoint_Selected].eResource].eContainerType == classResource.cResources[(int)frmAddResource.cResObject.eResource].eState)
					{

						frmAddResource.cResObject.cCDO.cSolarObject = cEarth;
						frmAddResource.cResObject.cCDO.dptPos = dptNewResource;
						cResSelected.cObjContainer.addResource_Object(ref frmAddResource.cResObject);
						for (int intCounter = 1; intCounter < frmAddResource.intQuantity; intCounter++)
						{
							classResourceObject cResObj = new classResourceObject();
							cResObj.eResource = frmAddResource.cResObject.eResource;
							cResObj.cCDO.cSolarObject = cEarth;
							cResObj.cCDO.dptPos = dptNewResource;
							cResSelected.cObjContainer.addResource_Object(ref cResObj);
						}
					}
					else
					{
						string strErrorMessage = "The container :"
										+ "\"" + cResSelected.eResource.ToString() + "\""
										+ " can only contain resources of state : "
										+ "\"" + classResource.cResources[(int)cResSelected.eResource].eContainerType.ToString() + "\""
										+ "\r\nEither change the container's eContainerType to " + "\"" + classResource.cResources[(int)frmAddResource.cResObject.eResource].eState.ToString() + "\""
										+ " or change the eState of the resource you are adding \"" + frmAddResource.cResObject.eResource.ToString()
										+ "\" to " + "\"" + classResource.cResources[(int)cResSelected.eResource].eContainerType.ToString() + "\"";


						MessageBox.Show(strErrorMessage, "type container error");
					}
				}
				else
				{

					frmAddResource.cResObject.cCDO.cSolarObject = cEarth;
					frmAddResource.cResObject.cCDO.dptPos = dptNewResource;
					cSI.cRooms[cmbRooms.SelectedIndex].addResObject(ref frmAddResource.cResObject);
					for (int intCounter = 1; intCounter < frmAddResource.intQuantity; intCounter++)
					{
						classResourceObject cResObj = new classResourceObject();
						cResObj.eResource = frmAddResource.cResObject.eResource;
						cResObj.cCDO.cSolarObject = cEarth;
						cResObj.cCDO.dptPos = dptNewResource;
						cSI.cRooms[cmbRooms.SelectedIndex].addResObject(ref cResObj);
					}
					drawScreen();
				}
			}
		}

		void Resource_Delete(object sender, EventArgs e)
		{
			if (intIndexPoint_Selected >= 0 && intIndexPoint_Selected < cSI_Room.cObjContainer.lcResourceObjects.Count)
			{
				classResourceObject cResObjRemoved = cSI_Room.cObjContainer.lcResourceObjects[intIndexPoint_Selected];
				cSI_Room.removeResObject(ref cResObjRemoved );
				drawScreen();
			}
		}

		void Resource_EditContainer(object sender, EventArgs e)
		{
			if (intIndexPoint_Selected >= 0 && intIndexPoint_Selected < cSI_Room.cObjContainer.lcResourceObjects.Count)
			{
				formEditContainer frmEditContainer = new formEditContainer();
				classResourceObject cResObjEdit = cSI_Room.cObjContainer.lcResourceObjects[intIndexPoint_Selected];
				frmEditContainer.ResourceObject = cResObjEdit;
				frmEditContainer.ShowDialog();
			}
		}

		void Astronaut_Add(object sender, EventArgs e)
		{
			classGameState.cControlAstronaut = new classAstronaut();
			classGameState.cControlAstronaut.RatingPilot = 75;
			classGameState.cControlAstronaut.RatingEngineer = 75;
			classGameState.cControlAstronaut.RatingChemist = 75;
			classGameState.cControlAstronaut.RatingGeologist = 75;

			int intNumCounter = 1;
			string strName = "Astronaut #" + intNumCounter.ToString("d2");

			while (AstronautNameExists(strName))
				strName = "Astronaut #" + (intNumCounter + 1).ToString("d2");

			classGameState.cControlAstronaut.Name = strName;
			classGameState.cControlAstronaut.cCDO.cSolarObject = cEarth;
			classGameState.cControlAstronaut.cCDO.dptPos = dptMouse.Copy();
			cSI_Room.addAstronaut(ref classGameState.cControlAstronaut);

			drawScreen();
			classGameState.cControlAstronaut = classGameState.cControlAstronaut;
		}

		public static bool AstronautNameExists(string strNewName)
		{
			strNewName = strNewName.ToUpper();
			for (int intAstronautCounter = 0; intAstronautCounter < classAstronaut.cAstronauts.Length; intAstronautCounter++)
			{
				if (classAstronaut.cAstronauts[intAstronautCounter].Name.ToUpper() == strNewName)
					return true;
			}
			return false;
		}

		void Astronaut_Delete(object sender, EventArgs e)
		{
			if (intIndexPoint_Selected >= 0 && intIndexPoint_Selected < cSI_Room.cObjContainer.lcAstronauts.Count)
			{
				classAstronaut cAstronautRemoved = cSI_Room.cObjContainer.lcAstronauts[intIndexPoint_Selected];

				for (int intAstronautCounter = 0; intAstronautCounter < classAstronaut.cAstronauts.Length; intAstronautCounter++)
				{
					if (classAstronaut.cAstronauts[intAstronautCounter] == cAstronautRemoved)
					{
						classAstronaut.cAstronauts[intAstronautCounter] = classAstronaut.cAstronauts[classAstronaut.cAstronauts.Length - 1];
						Array.Resize<classAstronaut>(ref classAstronaut.cAstronauts, classAstronaut.cAstronauts.Length - 1);
						break;
					}
				}

				cSI_Room.removeAstronaut(ref cAstronautRemoved);

				if (cAstronautRemoved == classGameState.cControlAstronaut)
				{
					if (classAstronaut.cAstronauts.Length > 0)
						classGameState.cControlAstronaut = classAstronaut.cAstronauts[0];
					else
						classGameState.cControlAstronaut = null;
				}

				drawScreen();
			}
		}

		void Astronaut_Edit(object sender, EventArgs e)
		{
			if (intIndexPoint_Selected >= 0 && intIndexPoint_Selected < cSI_Room.cObjContainer.lcAstronauts.Count)
			{
				classAstronaut cAstronautRemoved = cSI_Room.cObjContainer.lcAstronauts[intIndexPoint_Selected];
				formAstronaut_Edit frmAstronautEdit = new formAstronaut_Edit(ref cAstronautRemoved);

				frmAstronautEdit.ShowDialog();
			}
		}

		void Ship_Add(object sender, EventArgs e)
		{
			formSelectNewShipModel frmSelectionNewShipModel = new formSelectNewShipModel();
			frmSelectionNewShipModel.ShowDialog();

			classShip cShip = new classShip();
			cShip.eModel = frmSelectionNewShipModel.eModel;
			int intNumCounter = 1;
			string strName = "Ship #" + intNumCounter.ToString("d2");

			while (ShipNameExists(strName))
				strName = "Ship #" + (intNumCounter + 1).ToString("d2");

			cShip.Name = strName;
			cShip.cCDO.cSolarObject = cEarth;
			cShip.cCDO.dptPos = dptMouse.Copy();
			cSI_Room.addShip(ref cShip);

			drawScreen();
			formStructureInteriorEditor.bolChangesMadeSinceLastSave = true;
		}

		public static bool ShipNameExists(string strNewName)
		{
			strNewName = strNewName.ToUpper();
			for (int intShipCounter = 0; intShipCounter < classShip.cShips.Length; intShipCounter++)
			{
				if (classShip.cShips[intShipCounter].Name.ToUpper() == strNewName)
					return true;
			}
			return false;
		}

		void Ship_Delete(object sender, EventArgs e)
		{
			if (intShip_Selected >= 0 && intShip_Selected < cSI_Room.cObjContainer.lcShips.Count)
			{
				classShip cShipRemoved = cSI_Room.cObjContainer.lcShips[intShip_Selected];

				for (int intShipCounter = 0; intShipCounter < classShip.cShips.Length; intShipCounter++)
				{
					if (classShip.cShips[intShipCounter] == cShipRemoved)
					{
						classShip.cShips[intShipCounter] = classShip.cShips[classShip.cShips.Length - 1];
						Array.Resize<classShip>(ref classShip.cShips, classShip.cShips.Length - 1);
						break;
					}
				}

				cSI_Room.removeShip(ref cShipRemoved);

				intShip_NextSelected
					= intShip_Selected
					= -1;

				drawScreen();
			}
		}

		void Ship_EditStructure(object sender, EventArgs e)
		{
			if (intShip_Selected >= 0 && intShip_Selected < cSI_Room.cObjContainer.lcShips.Count)
			{
				classShip cShip = cSI_Room.cObjContainer.lcShips[intShip_Selected];
				
				classAstronaut cAstronaut_Remember = classGameState.cControlAstronaut;
				classMath.classDoubleCartesian dptViewFocus_Remember = classGameState.dptViewFocus;
				int intZoomIndex = classGameState.ZoomIndex;
				enuMode_StructureInteriorEditor eMode_remember = eMode;

				formStructureInteriorEditor frmEditShipStructure = new formStructureInteriorEditor(ref cShip.cSI);
				classGameState.dptViewFocus = new classMath.classDoubleCartesian();

				frmEditShipStructure.ShowDialog();
				cShip.cSI = frmEditShipStructure.cSI;

				buildPicView();
				classGameState.cControlAstronaut = cAstronaut_Remember;
				classGameState.dptViewFocus = dptViewFocus_Remember;
				classGameState.setZoom(intZoomIndex);
				eMode = eMode_remember;

				frmStructureInteriorEditor_Current = this;
			}
		}

		void Ship_EditName(object sender, EventArgs e)
		{
			if (intShip_Selected >= 0 && intShip_Selected < cSI_Room.cObjContainer.lcShips.Count)
			{
				classShip cShip = cSI_Room.cObjContainer.lcShips[intShip_Selected];
				formShip_EditName frmShipEditName = new formShip_EditName(ref cShip);
				frmShipEditName.ShowDialog();
			}
		}

		bool bolShipEdit_Rotate = false;
		void Ship_Rotate(object sender, EventArgs e)
		{
			bolShipEdit_Rotate = true;
			cmbLocation.Visible
				= cmbRooms.Visible
				= false;
			Focus();
		}

		void Room_Add(object sender, EventArgs e)
		{
			classStructureInterior_Room cNewRoom = new classStructureInterior_Room();
			Array.Resize<classStructureInterior_Room>(ref cSI.cRooms, cSI.cRooms.Length + 1);
			cSI.cRooms[cSI.cRooms.Length - 1] = cNewRoom;
			cNewRoom.intIndex = cSI.cRooms.Length - 1;

			cNewRoom.cPolygons = new classMath.classPolygon[1];
			cNewRoom.cPolygons[0] = new classMath.classPolygon();
			cNewRoom.cPolygons[0].dptArray = new classMath.classDoubleCartesian[4];
			cNewRoom.cPolygons[0].dptArray[0] = new classMath.classDoubleCartesian(-1, -1);
			cNewRoom.cPolygons[0].dptArray[1] = new classMath.classDoubleCartesian(1, -1);
			cNewRoom.cPolygons[0].dptArray[2] = new classMath.classDoubleCartesian(1, 1);
			cNewRoom.cPolygons[0].dptArray[3] = new classMath.classDoubleCartesian(-1, 1);
			cNewRoom.defineWallGrid();
			cNewRoom.cSI = cSI;
			string strNewRoomName = "New Room #";
			int intRoomNumberCounter = 1;

			while (!cNewRoom.setName(strNewRoomName + (intRoomNumberCounter++).ToString())) ;

			rebuildCmbRooms();
		}

		void Room_Delete(object sender, EventArgs e)
		{
			if (cSI.cRooms.Length == 1)
			{
				MessageBox.Show("Cannot erase the last remaining room in this structure", "error");
				return;
			}
			if (MessageBox.Show("Delete \"" + cSI_Room.Name + "\" room?", "delete room", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
			{
				cSI.cRooms[cSI_Room.intIndex] = cSI.cRooms[cSI.cRooms.Length - 1];
				Array.Resize<classStructureInterior_Room>(ref cSI.cRooms, cSI.cRooms.Length - 1);
				for (int intRoomCounter = 0; intRoomCounter < cSI.cRooms.Length; intRoomCounter++)
					cSI.cRooms[intRoomCounter].intIndex = intRoomCounter;
				// need to fix teleporters -> DEBUG-HERE

				if (cSI_Room.intIndex > 0)
					cSI_Room.intIndex--;

				cSI_Room = cSI.cRooms[cSI_Room.intIndex];
				rebuildCmbRooms();
			}
		}


		void Room_EditName(object sender, EventArgs e)
		{
			formEdit_StructureInteriorRoom_Name frmEditRooName = new formEdit_StructureInteriorRoom_Name(ref cSI_Room);
			frmEditRooName.ShowDialog();
			rebuildCmbRooms();
		}

		void TeleporterCoupling_Add(object sender, EventArgs e)
		{
		}

		void TeleporterCoupling_Delete(object sender, EventArgs e)
		{
		}

		void Teleporter_EditName(object sender, EventArgs e)
		{
		}

		void Point_Add()
		{
			Array.Resize<classMath.classDoubleCartesian>(ref cSI_Room.cPolygons[intPolygon_Selected].dptArray, cSI_Room.cPolygons[intPolygon_Selected].dptArray.Length + 1);
			for (int intPtCounter = cSI_Room.cPolygons[intPolygon_Selected].dptArray.Length - 1; intPtCounter > intIndexPoint_Selected; intPtCounter--)
			{
				cSI_Room.cPolygons[intPolygon_Selected].dptArray[intPtCounter] = cSI_Room.cPolygons[intPolygon_Selected].dptArray[intPtCounter - 1].Copy();
			}
			drawScreen();
		}

		void Point_Add_After(object sender, EventArgs e)
		{
			switch (eMode)
			{
				case enuMode_StructureInteriorEditor.edit_Structure:
					if (intIndexPoint_NextSelect  >= 0 && intPolygon_NextSelected >= 0)
					{
						intIndexPoint_Selected = intIndexPoint_NextSelect;
						intPolygon_Selected = intPolygon_NextSelected;
						intIndexPoint_NextSelect  = -1;
						intPolygon_NextSelected= -1;
					}
					if (intIndexPoint_Selected >= 0 && intPolygon_Selected >= 0)
					{
						Point_Add();
						if (intIndexPoint_Selected > 0)
							cSI_Room.cPolygons[intPolygon_Selected].dptArray[intIndexPoint_Selected] = classMath.findCenterOfLine(cSI_Room.cPolygons[intPolygon_Selected].dptArray[intIndexPoint_Selected], cSI_Room.cPolygons[intPolygon_Selected].dptArray[intIndexPoint_Selected - 1]);
						else
							cSI_Room.cPolygons[intPolygon_Selected].dptArray[intIndexPoint_Selected] = classMath.findCenterOfLine(cSI_Room.cPolygons[intPolygon_Selected].dptArray[intIndexPoint_Selected], cSI_Room.cPolygons[intPolygon_Selected].dptArray[cSI_Room.cPolygons[intPolygon_Selected].dptArray.Length -1]);
					}
					break;
			}
		}


		void Point_Add_Before(object sender, EventArgs e)
		{
			switch (eMode)
			{
				case enuMode_StructureInteriorEditor.edit_Structure:
					if (intIndexPoint_NextSelect >= 0 && intPolygon_NextSelected >= 0)
					{
						intIndexPoint_Selected = intIndexPoint_NextSelect;
						intPolygon_Selected = intPolygon_NextSelected;
						intIndexPoint_NextSelect = -1;
						intPolygon_NextSelected = -1;
					}
					if (intIndexPoint_Selected >= 0 && intPolygon_Selected >= 0)
					{
						Point_Add();
						if (intIndexPoint_Selected < cSI_Room.cPolygons[intPolygon_Selected].dptArray.Length -2)
							cSI_Room.cPolygons[intPolygon_Selected].dptArray[intIndexPoint_Selected+1] = classMath.findCenterOfLine(cSI_Room.cPolygons[intPolygon_Selected].dptArray[intIndexPoint_Selected], cSI_Room.cPolygons[intPolygon_Selected].dptArray[intIndexPoint_Selected +2]);
						else
							cSI_Room.cPolygons[intPolygon_Selected].dptArray[intIndexPoint_Selected+1] = classMath.findCenterOfLine(cSI_Room.cPolygons[intPolygon_Selected].dptArray[intIndexPoint_Selected], cSI_Room.cPolygons[intPolygon_Selected].dptArray[0]);
					}
					break;
			}
		}

		void Point_Delete(object sender, EventArgs e)
		{
			switch (eMode)
			{
				case enuMode_StructureInteriorEditor.edit_Structure:
					if (intIndexPoint_NextSelect >= 0)
					{
						intIndexPoint_Selected = intIndexPoint_NextSelect;
						intPolygon_Selected = intPolygon_NextSelected;
						intIndexPoint_NextSelect = -1;
					}
					for (int intPointCounter = intIndexPoint_Selected; intPointCounter < cSI_Room.cPolygons[intPolygon_Selected].dptArray.Length - 1; intPointCounter++)
					{
						cSI_Room.cPolygons[intPolygon_Selected].dptArray[intPointCounter] = cSI_Room.cPolygons[intPolygon_Selected].dptArray[intPointCounter + 1];
					}
					Array.Resize<classMath.classDoubleCartesian>(ref cSI_Room.cPolygons[intPolygon_Selected].dptArray, cSI_Room.cPolygons[intPolygon_Selected].dptArray.Length - 1);
					drawScreen();
					if (intIndexPoint_Selected >= cSI_Room.cPolygons[intPolygon_Selected].dptArray.Length)
						intIndexPoint_Selected = cSI_Room.cPolygons[intPolygon_Selected].dptArray.Length - 1;
					break;

			}

		}

		void picView_MouseUp(object sender, MouseEventArgs e)
		{
			if (dptGrab != null)
			{
				dptGrab = null;
				Cursor = Cursors.Arrow;
			}

			switch (eMode)
			{
				case enuMode_StructureInteriorEditor.Move:
					if ((enuAstronaut_Arm_Configurations)classGameState.cControlAstronaut.cSprConInfo_Arm.intIndex != enuAstronaut_Arm_Configurations.pull_back
						 && (enuAstronaut_Arm_Configurations)classGameState.cControlAstronaut.cSprConInfo_Arm.intIndex != enuAstronaut_Arm_Configurations.retracted)
					{
						classGameState.cControlAstronaut.cSprConInfo_Arm.intIndex = (int)enuAstronaut_Arm_Configurations.pull_back;
						classGameState.cControlAstronaut.cSprConInfo_Arm.intStep = 0;
					}
					break;
			}

			switch (e.Button)
			{
				case System.Windows.Forms.MouseButtons.Left:
					bolMouseDown[(int)enuMouseButtons.Left] = false;
					break;

				case System.Windows.Forms.MouseButtons.Middle:
					bolMouseDown[(int)enuMouseButtons.Middle] = false;
					break;

				case System.Windows.Forms.MouseButtons.Right:
					bolMouseDown[(int)enuMouseButtons.Right] = false;
					break;
			}
		}

		void grabScreen()
		{
			Cursor = Cursors.Hand;
			dptGrab = dptMouse.Copy();
		}

		void picView_MouseDown(object sender, MouseEventArgs e)
		{
			switch (e.Button)
			{
				case System.Windows.Forms.MouseButtons.Left:
					bolMouseDown[(int)enuMouseButtons.Left] = true;
					switch (eMode)
					{
						case enuMode_StructureInteriorEditor.edit_Resources:
							if (intIndexPoint_NextSelect >= 0)
							{
								DullPoint(intIndexPoint_Selected);
								intIndexPoint_Selected = intIndexPoint_NextSelect;
								HighlightPoint(intIndexPoint_Selected);
								intIndexPoint_NextSelect = -1;
							}
							else
								grabScreen();
							break;

						case enuMode_StructureInteriorEditor.edit_Astronauts:
							if (intIndexPoint_NextSelect >= 0)
							{
								DullPoint(intIndexPoint_Selected);
								intIndexPoint_Selected = intIndexPoint_NextSelect;
								HighlightPoint(intIndexPoint_Selected);
								intIndexPoint_NextSelect = -1;
								classGameState.cControlAstronaut = cSI_Room.cObjContainer.lcAstronauts[intIndexPoint_Selected];
								classGameState.cTrackObject = classGameState.cControlAstronaut.cCDO;
							}
							else
								grabScreen();
							break;

						case enuMode_StructureInteriorEditor.edit_Ships:
							if (bolShipEdit_Rotate)
							{
								bolShipEdit_Rotate = false;
								cmbLocation.Visible
									= cmbRooms.Visible
									= true;
							}
							else if (intShip_NextSelected >= 0)
							{
								DullPoint(intShip_Selected);
								intShip_Selected = intShip_NextSelected;
								HighlightPoint(intShip_Selected);
								intShip_NextSelected = -1;
							}
							else
								grabScreen();
							break;

						case enuMode_StructureInteriorEditor.edit_Structure:
							if (intIndexPoint_NextSelect >= 0 && intPolygon_NextSelected >= 0)
							{
								DullPoint(intIndexPoint_Selected, intPolygon_Selected);
								intIndexPoint_Selected = intIndexPoint_NextSelect;
								intPolygon_Selected = intPolygon_NextSelected;
								HighlightPoint(intIndexPoint_Selected, intPolygon_Selected);
								intIndexPoint_NextSelect = -1;
							}
							else
								grabScreen();
							break;

						case enuMode_StructureInteriorEditor.edit_Teleporters:
							if (intTeleporter_NextSelected >= 0)
							{
								DullPoint(intTeleporter_Selected, eTelePortEdit_PointSelection);
								intTeleporter_Selected = intTeleporter_NextSelected;
								eTelePortEdit_PointSelection = eTelePortEdit_PointSelection_Next;
								HighlightPoint(intTeleporter_Selected, eTelePortEdit_PointSelection);
								intTeleporter_NextSelected = -1;
							}
							else
								grabScreen();
							break;

						case enuMode_StructureInteriorEditor.Move:
							classGameState.cControlAstronaut.bolHandAction = true;
							break;
					}

					break;

				case System.Windows.Forms.MouseButtons.Middle:
					bolMouseDown[(int)enuMouseButtons.Middle] = true;
					break;

				case System.Windows.Forms.MouseButtons.Right:
					bolMouseDown[(int)enuMouseButtons.Right] = true;
					break;
			}
		}

		void picView_MouseMove(object sender, MouseEventArgs e)
		{
			ptMouse = new Point(e.X, e.Y);
			classMath.classDoubleCartesian dptMouseFromCenterScreen = new classMath.classDoubleCartesian(classGameState.ptScreenCenter.X - ptMouse.X,
																										 classGameState.ptScreenCenter.Y - ptMouse.Y).multiplyFactor(1.0 / classGameState.dblScreenSizeFactor);

			dptMouse = classGameState.dptViewFocus.Sub(dptMouseFromCenterScreen);

			if (dptGrab != null)
			{ // move focus with screen-grab
				classGameState.dptViewFocus = classGameState.dptViewFocus.Add( dptGrab.Sub(dptMouse));

				drawScreen();
				return;
			}

			double dbleLimit = 10;
			switch (eMode)
			{
				case enuMode_StructureInteriorEditor.edit_Structure:
					if (bolMouseDown[(int)enuMouseButtons.Left])
					{
						if (intIndexPoint_Selected >= 0 && intPolygon_Selected >= 0)
						{
							cSI_Room.cPolygons[intPolygon_Selected].dptArray[intIndexPoint_Selected] = dptMouse;
							cSI_Room.defineWallGrid();
							drawScreen();
							bolChangesMadeSinceLastSave = true;
						}
					}
					else
					{
						double dblBestDistance = 10000;
						int intBestChoice_Point = -1, intBestChoice_Polygon = -1;
						for (int intPolygonCounter = 0; intPolygonCounter < cSI_Room.cPolygons.Length; intPolygonCounter++)
						{
							for (int intPointCounter = 0; intPointCounter < cSI_Room.cPolygons[intPolygonCounter].dptArray.Length; intPointCounter++)
							{
								Point pt = classLandscape.getPointScreen(cSI_Room.cPolygons[intPolygonCounter].dptArray[intPointCounter], classGameState.dptViewFocus, classGameState.ptScreenCenter);
								double dblDistance = classMath.distanceBetweenTwoPoints(ptMouse, pt);
								if (dblDistance < dbleLimit && dblDistance < dblBestDistance)
								{
									dblBestDistance = dblDistance;
									intBestChoice_Point = intPointCounter;
									intBestChoice_Polygon = intPolygonCounter;
								}
							}
						}

						if (intIndexPoint_NextSelect == intIndexPoint_Selected)
							BoldPoint(intIndexPoint_Selected, intPolygon_Selected);
						else
							DullPoint(intIndexPoint_NextSelect, intPolygon_NextSelected);

						intIndexPoint_NextSelect = intBestChoice_Point;
						intPolygon_NextSelected = intBestChoice_Polygon;
						HighlightPoint(intIndexPoint_NextSelect, intPolygon_NextSelected);
					}
					break;

				case enuMode_StructureInteriorEditor.edit_Resources:
					if (bolMouseDown[(int)enuMouseButtons.Left])
					{
						if (intIndexPoint_Selected >= 0)
						{
							bolChangesMadeSinceLastSave = true;
							Point ptGridWall_Start = cSI_Room.getWallGridLinePtIndexFromDpt(cSI_Room.cObjContainer.lcResourceObjects[intIndexPoint_Selected].cCDO.dptPos);
							classStructureWallGridLineIndexArray cGridWall_Start = cSI_Room.WallGrid[ptGridWall_Start.X, ptGridWall_Start.Y];
							classResourceObject cResObj = cSI_Room.cObjContainer.lcResourceObjects[intIndexPoint_Selected];
							cGridWall_Start.removeResObject(ref cResObj);

							cResObj.cCDO.dptPos = dptMouse;

							Point ptGridWall_End = cSI_Room.getWallGridLinePtIndexFromDpt(cSI_Room.cObjContainer.lcResourceObjects[intIndexPoint_Selected].cCDO.dptPos);
							classStructureWallGridLineIndexArray cGridWall_End = cSI_Room.WallGrid[ptGridWall_End.X, ptGridWall_End.Y];
							cGridWall_End.addResObject(ref cResObj);

							cSI_Room.defineWallGrid();
							drawScreen();
						}
					}
					else
					{
						double dblBestDistance = 10000;
						int intBestChoice_Point = -1;
						for (int intResourceCounter = 0; intResourceCounter < cSI_Room.cObjContainer.lcResourceObjects.Count; intResourceCounter++)
						{
							Point pt = classLandscape.getPointScreen(cSI_Room.cObjContainer.lcResourceObjects[intResourceCounter].cCDO.dptPos, classGameState.dptViewFocus, classGameState.ptScreenCenter);
							double dblDistance = classMath.distanceBetweenTwoPoints(ptMouse, pt);
							if (dblDistance < dbleLimit && dblDistance < dblBestDistance)
							{
								dblBestDistance = dblDistance;
								intBestChoice_Point = intResourceCounter;
							}
						}

						if (intIndexPoint_NextSelect == intIndexPoint_Selected)
							BoldPoint(intIndexPoint_Selected);
						else
							DullPoint(intIndexPoint_NextSelect);
						if (intIndexPoint_Selected >= 0 && intBestChoice_Point < 0) DullPoint(intIndexPoint_Selected);
						intIndexPoint_Selected
							= intIndexPoint_NextSelect
							= intBestChoice_Point; ;
						HighlightPoint(intIndexPoint_NextSelect);
					}
					break;

				case enuMode_StructureInteriorEditor.edit_Astronauts:
					if (bolMouseDown[(int)enuMouseButtons.Left])
					{
						if (intIndexPoint_Selected >= 0)
						{
							bolChangesMadeSinceLastSave = true;
							Point ptGridWall_Start = cSI_Room.getWallGridLinePtIndexFromDpt(cSI_Room.cObjContainer.lcAstronauts[intIndexPoint_Selected].cCDO.dptPos);
							classStructureWallGridLineIndexArray cGridWall_Start = cSI_Room.WallGrid[ptGridWall_Start.X, ptGridWall_Start.Y];
							classAstronaut cAstronaut = cSI_Room.cObjContainer.lcAstronauts[intIndexPoint_Selected];
							cGridWall_Start.removeAstronaut(ref cAstronaut);

							cAstronaut.cCDO.dptPos = dptMouse;

							Point ptGridWall_End = cSI_Room.getWallGridLinePtIndexFromDpt(cSI_Room.cObjContainer.lcAstronauts[intIndexPoint_Selected].cCDO.dptPos);
							classStructureWallGridLineIndexArray cGridWall_End = cSI_Room.WallGrid[ptGridWall_End.X, ptGridWall_End.Y];
							cGridWall_End.removeAstronaut(ref cAstronaut);

							cSI_Room.defineWallGrid();
							drawScreen();
						}
					}
					else
					{
						double dblBestDistance = 10000;
						int intBestChoice_Point = -1;
						for (int intResourceCounter = 0; intResourceCounter < cSI_Room.cObjContainer.lcAstronauts.Count; intResourceCounter++)
						{
							bolChangesMadeSinceLastSave = true;
							Point pt = classLandscape.getPointScreen(cSI_Room.cObjContainer.lcAstronauts[intResourceCounter].cCDO.dptPos, classGameState.dptViewFocus, classGameState.ptScreenCenter);
							double dblDistance = classMath.distanceBetweenTwoPoints(ptMouse, pt);
							if (dblDistance < dbleLimit && dblDistance < dblBestDistance)
							{
								dblBestDistance = dblDistance;
								intBestChoice_Point = intResourceCounter;
							}
						}

						if (intIndexPoint_NextSelect == intIndexPoint_Selected)
							BoldPoint(intIndexPoint_Selected);
						else
							DullPoint(intIndexPoint_NextSelect);
						if (intIndexPoint_Selected >= 0 && intBestChoice_Point < 0) DullPoint(intIndexPoint_Selected);
						intIndexPoint_Selected
							= intIndexPoint_NextSelect
							= intBestChoice_Point; ;
						HighlightPoint(intIndexPoint_NextSelect);
					}
					break;

				case enuMode_StructureInteriorEditor.edit_Ships:
					if (bolMouseDown[(int)enuMouseButtons.Left])
					{
						if (intShip_Selected >= 0)
						{
							bolChangesMadeSinceLastSave = true;
							Point ptGridWall_Start = cSI_Room.getWallGridLinePtIndexFromDpt(cSI_Room.cObjContainer.lcShips[intShip_Selected].cCDO.dptPos);
							classStructureWallGridLineIndexArray cGridWall_Start = cSI_Room.WallGrid[ptGridWall_Start.X, ptGridWall_Start.Y];
							classShip cShipSelected = cSI_Room.cObjContainer.lcShips[intShip_Selected];
							cGridWall_Start.removeShip(ref cShipSelected);

							cSI_Room.cObjContainer.lcShips[intShip_Selected].cCDO.dptPos = dptMouse;

							Point ptGridWall_End = cSI_Room.getWallGridLinePtIndexFromDpt(cSI_Room.cObjContainer.lcShips[intShip_Selected].cCDO.dptPos);
							classStructureWallGridLineIndexArray cGridWall_End = cSI_Room.WallGrid[ptGridWall_End.X, ptGridWall_End.Y];
							cGridWall_End.removeShip(ref cShipSelected);

							cSI_Room.defineWallGrid();
							drawScreen();
						}
					}
					else
					{
						double dblBestDistance = 10000;
						int intBestChoice_Point = -1;
						for (int intShipCounter = 0; intShipCounter < cSI_Room.cObjContainer.lcShips.Count; intShipCounter++)
						{
							Point pt = classLandscape.getPointScreen(cSI_Room.cObjContainer.lcShips[intShipCounter].cCDO.dptPos, classGameState.dptViewFocus, classGameState.ptScreenCenter);
							double dblDistance = classMath.distanceBetweenTwoPoints(ptMouse, pt);
							if (dblDistance < dbleLimit && dblDistance < dblBestDistance)
							{
								dblBestDistance = dblDistance;
								intBestChoice_Point = intShipCounter;
							}
						}

						if (intShip_NextSelected == intShip_Selected)
							BoldPoint(intShip_Selected);
						else
							DullPoint(intShip_NextSelected);
						if (intShip_Selected >= 0 && intBestChoice_Point < 0) DullPoint(intShip_Selected);
						intShip_Selected
							= intShip_NextSelected
							= intBestChoice_Point; ;
						HighlightPoint(intShip_NextSelected);
					}
					break;

				case enuMode_StructureInteriorEditor.edit_Teleporters:
					if (bolMouseDown[(int)enuMouseButtons.Left])
					{
						if (intTeleporter_Selected >= 0 && intTeleporter_Selected < cSI_Room.cTeleporters.Length)
						{
							bolChangesMadeSinceLastSave = true;
							switch (eTelePortEdit_PointSelection)
							{
								case enuTelePortEdit_PointSelection.Pos:// moving a teleporter
									cSI_Room.cTeleporters[intTeleporter_Selected].dptPos = dptMouse;
									cSI_Room.defineWallGrid();
									drawScreen();
									break;

								case enuTelePortEdit_PointSelection.RadArrivingObject: // position arriving vector
									cSI_Room.cTeleporters[intTeleporter_Selected].cRadPlaceArrivingObject = classMath.convertCarToRad(cSI_Room.cTeleporters[intTeleporter_Selected].dptPos, dptMouse);
									drawScreen();
									break;

								case enuTelePortEdit_PointSelection.Radius: // resize radius
									cSI_Room.cTeleporters[intTeleporter_Selected].dblRadius = classMath.distanceBetweenTwoPoints(cSI_Room.cTeleporters[intTeleporter_Selected].dptPos, dptMouse);
									if (cSI_Room.cTeleporters[intTeleporter_Selected].cTeleporterLink.cSI_Room == null)
										cSI_Room.cTeleporters[intTeleporter_Selected].cTeleporterLink.dblRadius = cSI_Room.cTeleporters[intTeleporter_Selected].dblRadius;
									drawScreen();
									break;

								case enuTelePortEdit_PointSelection.RealWorldHeight: // resize height & drawSize
									cSI_Room.cTeleporters[intTeleporter_Selected].Coupling.RealWorldHeight = formMarsMission.ConvertGWUnitsToRWUnits(classMath.distanceBetweenTwoPoints(cSI_Room.cTeleporters[intTeleporter_Selected].dptPos, dptMouse)) * 2;
									drawScreen();
									break;
							}
						}
					}
					else
					{ // find the teleporter nearest to the mouse cursor
						double dblBestDistance = 10000;
						double dblDistance = 0;
						int intBestChoice_Teleporter = -1;
						enuTelePortEdit_PointSelection eBestChoice = enuTelePortEdit_PointSelection.Pos;
						for (int intTeleporterCounter = 0; intTeleporterCounter < cSI_Room.cTeleporters.Length; intTeleporterCounter++)
						{
							/// measure distance to radius of teleporter
							classMath.classDoubleCartesian dptRadius = classMath.convertRadToDCar(cSI_Room.cTeleporters[intTeleporterCounter].dptPos, new classMath.classRadialCoor(5.0 / 4.0 * Math.PI, cSI_Room.cTeleporters[intTeleporterCounter].dblRadius));
							Point ptRadius = classLandscape.getPointScreen(dptRadius, classGameState.dptViewFocus, classGameState.ptScreenCenter);
							dblDistance = classMath.distanceBetweenTwoPoints(ptRadius, ptMouse);
							Text = dblDistance.ToString("f2");
							if (dblDistance < dbleLimit && dblDistance < dblBestDistance)
							{
								dblBestDistance = dblDistance;
								intBestChoice_Teleporter = intTeleporterCounter;
								eBestChoice = enuTelePortEdit_PointSelection.Radius;
							}

							// measure distance to radObjectArrive of Teleporter
							classMath.classDoubleCartesian dptObjectArrive = classMath.convertRadToDCar(cSI_Room.cTeleporters[intTeleporterCounter].dptPos, cSI_Room.cTeleporters[intTeleporterCounter].cRadPlaceArrivingObject);
							Point ptObjectArrive = classLandscape.getPointScreen(dptObjectArrive, classGameState.dptViewFocus, classGameState.ptScreenCenter);
							dblDistance = classMath.distanceBetweenTwoPoints(ptObjectArrive, ptMouse);
							if (dblDistance < dbleLimit && dblDistance < dblBestDistance)
							{
								dblBestDistance = dblDistance;
								intBestChoice_Teleporter = intTeleporterCounter;
								eBestChoice = enuTelePortEdit_PointSelection.RadArrivingObject;
							}

							/// measure distance to center of teleporter
							Point ptTeleporter = classLandscape.getPointScreen(cSI_Room.cTeleporters[intTeleporterCounter].dptPos, classGameState.dptViewFocus, classGameState.ptScreenCenter);
							dblDistance = classMath.distanceBetweenTwoPoints(ptMouse, ptTeleporter);
							if (dblDistance < dbleLimit && dblDistance < dblBestDistance)
							{
								dblBestDistance = dblDistance;
								intBestChoice_Teleporter = intTeleporterCounter;
								eBestChoice = enuTelePortEdit_PointSelection.Pos;
							}

							/// measure distance to real-world-height
							classMath.classDoubleCartesian dptRealWorldHeight = cSI_Room.cTeleporters[intTeleporterCounter].dptPos.Copy();
							dptRealWorldHeight.Y -= formMarsMission.ConvertRWUnitsToGWUnits(cSI_Room.cTeleporters[intTeleporterCounter].Coupling.RealWorldHeight / 2);
							Point ptRealWorldHeight = classLandscape.getPointScreen(dptRealWorldHeight, classGameState.dptViewFocus, classGameState.ptScreenCenter);
							dblDistance = classMath.distanceBetweenTwoPoints(ptMouse, ptRealWorldHeight);
							if (dblDistance < dbleLimit && dblDistance < dblBestDistance)
							{
								dblBestDistance = dblDistance;
								intBestChoice_Teleporter = intTeleporterCounter;
								eBestChoice = enuTelePortEdit_PointSelection.RealWorldHeight;
							}
						}

						if (intTeleporter_NextSelected == intTeleporter_Selected && eTelePortEdit_PointSelection_Next == eBestChoice)
							BoldPoint(intTeleporter_Selected, eBestChoice);
						else
							DullPoint(intTeleporter_NextSelected, eBestChoice);

						intTeleporter_NextSelected = intBestChoice_Teleporter;
						eTelePortEdit_PointSelection_Next = eBestChoice;
						HighlightPoint(intTeleporter_NextSelected, eBestChoice);
					}
					break;
			}
			drawScreen();
		}
		#region drawPoints

		#region dullPoints
		void DullPoint(int intPointIndex, enuTelePortEdit_PointSelection ePointSelection)
		{
			if (intPointIndex >= 0 && intPointIndex < cSI_Room.cTeleporters.Length)
			{
				switch (ePointSelection)
				{
					case enuTelePortEdit_PointSelection.Pos:
						Point ptEditTeleporter = classLandscape.getPointScreen(cSI_Room.cTeleporters[intPointIndex].dptPos, classGameState.dptViewFocus, classGameState.ptScreenCenter);
						classGameState.g.DrawEllipse(pDull, new Rectangle(ptEditTeleporter.X - intCircleRadius, ptEditTeleporter.Y - intCircleRadius, 2 * intCircleRadius, 2 * intCircleRadius));
						break;

					case enuTelePortEdit_PointSelection.RadArrivingObject:
						classMath.classDoubleCartesian dptArrivingPoint = classMath.convertRadToDCar(cSI_Room.cTeleporters[intPointIndex].dptPos, cSI_Room.cTeleporters[intPointIndex].cRadPlaceArrivingObject);
						Point ptEditTeleporter_Arriving = classLandscape.getPointScreen(dptArrivingPoint, classGameState.dptViewFocus, classGameState.ptScreenCenter);
						classGameState.g.DrawEllipse(pDull, new Rectangle(ptEditTeleporter_Arriving.X - intCircleRadius, ptEditTeleporter_Arriving.Y - intCircleRadius, 2 * intCircleRadius, 2 * intCircleRadius));
						break;

					case enuTelePortEdit_PointSelection.Radius:
						classMath.classDoubleCartesian dptRadius = classMath.convertRadToDCar(cSI_Room.cTeleporters[intPointIndex].dptPos, new classMath.classRadialCoor(5.0 / 4.0 * Math.PI, cSI_Room.cTeleporters[intPointIndex].dblRadius));
						Point ptEditTeleporter_Radius = classLandscape.getPointScreen(dptRadius, classGameState.dptViewFocus, classGameState.ptScreenCenter);
						classGameState.g.DrawEllipse(pDull, new Rectangle(ptEditTeleporter_Radius.X - intCircleRadius, ptEditTeleporter_Radius.Y - intCircleRadius, 2 * intCircleRadius, 2 * intCircleRadius));
						break;

					case enuTelePortEdit_PointSelection.RealWorldHeight:
						classMath.classDoubleCartesian dptRealWorldHeight = cSI_Room.cTeleporters[intPointIndex].dptPos.Copy();
						dptRealWorldHeight.Y -= formMarsMission.ConvertRWUnitsToGWUnits(cSI_Room.cTeleporters[intPointIndex].Coupling.RealWorldHeight / 2);
						Point ptRealworldHeight = classLandscape.getPointScreen(dptRealWorldHeight, classGameState.dptViewFocus, classGameState.ptScreenCenter);
						classGameState.g.DrawEllipse(pDull, new Rectangle(ptRealworldHeight.X - 2, ptRealworldHeight.Y - 2, 4, 4));
						break;
				}
			}
		}
	

		void DullPoint(int intPointIndex)
		{
			switch (eMode)
			{
				case enuMode_StructureInteriorEditor.edit_Teleporters:
					if (intPointIndex >= 0 && intPointIndex < cSI_Room.cTeleporters.Length)
					{
						DullPoint(intPointIndex, eTelePortEdit_PointSelection);
						classGameState.picView.Image = classGameState.bmpViewScreen;
					}
					break;

				case enuMode_StructureInteriorEditor.edit_Resources:
					if (intPointIndex >= 0 && intPointIndex < cSI_Room.cObjContainer.lcResourceObjects.Count)
					{
						Point ptEditResource = classLandscape.getPointScreen(cSI_Room.cObjContainer.lcResourceObjects[intPointIndex].cCDO.dptPos, classGameState.dptViewFocus, classGameState.ptScreenCenter);
						classGameState.g.DrawEllipse(pDull, new Rectangle(ptEditResource.X - intCircleRadius, ptEditResource.Y - intCircleRadius, 2 * intCircleRadius, 2 * intCircleRadius));
						classGameState.picView.Image = classGameState.bmpViewScreen;
					}
					break;

				case enuMode_StructureInteriorEditor.edit_Astronauts:
					if (intPointIndex >= 0 && intPointIndex < cSI_Room.cObjContainer.lcAstronauts.Count)
					{
						Point ptEditAstronaut = classLandscape.getPointScreen(cSI_Room.cObjContainer.lcAstronauts[intPointIndex].cCDO.dptPos, classGameState.dptViewFocus, classGameState.ptScreenCenter);
						classGameState.g.DrawEllipse(pDull, new Rectangle(ptEditAstronaut.X - intCircleRadius, ptEditAstronaut.Y - intCircleRadius, 2 * intCircleRadius, 2 * intCircleRadius));
						classGameState.picView.Image = classGameState.bmpViewScreen;
					}
					break;

				case enuMode_StructureInteriorEditor.edit_Ships:
					if (intPointIndex >= 0 && intPointIndex < cSI_Room.cObjContainer.lcShips.Count)
					{
						//DullPoint(intPointIndex);
						classGameState.picView.Image = classGameState.bmpViewScreen;
					}
					break;
			}
		}

		void DullPoint(int intPointIndex, int intPolygonIndex)
		{
			if (intPolygonIndex >= 0 && intPolygonIndex < cSI_Room.cPolygons.Length
				&& intPointIndex >= 0 && intPointIndex < cSI_Room.cPolygons[intPolygonIndex].dptArray.Length)
			{
				Point pt = classLandscape.getPointScreen(cSI_Room.cPolygons[intPolygonIndex].dptArray[intPointIndex], classGameState.dptViewFocus, classGameState.ptScreenCenter);
				classGameState.g.DrawEllipse(pDull, new Rectangle(pt.X - intCircleRadius, pt.Y - intCircleRadius, 2 * intCircleRadius, 2 * intCircleRadius));
				classGameState.picView.Image = classGameState.bmpViewScreen;
			}
		}

		
		#endregion

		#region highlightPoints
		void HighlightPoint(int intPointIndex, enuTelePortEdit_PointSelection ePointSelection)
		{
			if (intPointIndex >= 0 && intPointIndex < cSI_Room.cTeleporters.Length)
			{
				switch (ePointSelection)
				{
					case enuTelePortEdit_PointSelection.Pos:
						Point ptEditTeleporter = classLandscape.getPointScreen(cSI_Room.cTeleporters[intPointIndex].dptPos, classGameState.dptViewFocus, classGameState.ptScreenCenter);
						classGameState.g.DrawEllipse(pHighlight, new Rectangle(ptEditTeleporter.X - intCircleRadius, ptEditTeleporter.Y - intCircleRadius, 2 * intCircleRadius, 2 * intCircleRadius));
						break;

					case enuTelePortEdit_PointSelection.RadArrivingObject:
						classMath.classDoubleCartesian dptArrivingPoint = classMath.convertRadToDCar(cSI_Room.cTeleporters[intPointIndex].dptPos, cSI_Room.cTeleporters[intPointIndex].cRadPlaceArrivingObject);
						Point ptEditTeleporter_Arriving = classLandscape.getPointScreen(dptArrivingPoint, classGameState.dptViewFocus, classGameState.ptScreenCenter);
						classGameState.g.DrawEllipse(pHighlight, new Rectangle(ptEditTeleporter_Arriving.X - intCircleRadius, ptEditTeleporter_Arriving.Y - intCircleRadius, 2 * intCircleRadius, 2 * intCircleRadius));
						break;

					case enuTelePortEdit_PointSelection.Radius:
						classMath.classDoubleCartesian dptRadius = classMath.convertRadToDCar(cSI_Room.cTeleporters[intPointIndex].dptPos, new classMath.classRadialCoor(5.0 / 4.0 * Math.PI, cSI_Room.cTeleporters[intPointIndex].dblRadius));
						Point ptEditTeleporter_Radius = classLandscape.getPointScreen(dptRadius, classGameState.dptViewFocus, classGameState.ptScreenCenter);
						classGameState.g.DrawEllipse(pHighlight, new Rectangle(ptEditTeleporter_Radius.X - intCircleRadius, ptEditTeleporter_Radius.Y - intCircleRadius, 2 * intCircleRadius, 2 * intCircleRadius));
						break;

					case enuTelePortEdit_PointSelection.RealWorldHeight:
						classMath.classDoubleCartesian dptRealWorldHeight = cSI_Room.cTeleporters[intPointIndex].dptPos.Copy();
						dptRealWorldHeight.Y -= formMarsMission.ConvertRWUnitsToGWUnits(cSI_Room.cTeleporters[intPointIndex].Coupling.RealWorldHeight / 2);
						Point ptRealworldHeight = classLandscape.getPointScreen(dptRealWorldHeight, classGameState.dptViewFocus, classGameState.ptScreenCenter);
						classGameState.g.DrawEllipse(pDull, new Rectangle(ptRealworldHeight.X - 2, ptRealworldHeight.Y - 2, 4, 4));
						break;
				}
			}
		}

		void HighlightPoint(int intPointIndex, int intPolygonIndex)
		{
			if (intPolygonIndex >= 0 && intPolygonIndex < cSI_Room.cPolygons.Length
				&& intPointIndex >= 0 && intPointIndex < cSI_Room.cPolygons[intPolygonIndex].dptArray.Length)
			{
				Point pt = classLandscape.getPointScreen(cSI_Room.cPolygons[intPolygonIndex].dptArray[intPointIndex], classGameState.dptViewFocus, classGameState.ptScreenCenter);
				classGameState.g.DrawEllipse(pHighlight, new Rectangle(pt.X - intCircleRadius, pt.Y - intCircleRadius, 2 * intCircleRadius, 2 * intCircleRadius));
			}
		}
	
		void HighlightPoint(int intPointIndex)
		{
			switch (eMode)
			{
				case enuMode_StructureInteriorEditor.edit_Teleporters:
					if (intPointIndex >= 0 && intPointIndex < cSI_Room.cTeleporters.Length)
					{
						HighlightPoint(intPointIndex, eTelePortEdit_PointSelection);
						classGameState.picView.Image = classGameState.bmpViewScreen;
					}
					break;

				case enuMode_StructureInteriorEditor.edit_Resources:
					if (intPointIndex >= 0 && intPointIndex < cSI_Room.cObjContainer.lcResourceObjects.Count)
					{
						Point ptEditResource = classLandscape.getPointScreen(cSI_Room.cObjContainer.lcResourceObjects[intPointIndex].cCDO.dptPos, classGameState.dptViewFocus, classGameState.ptScreenCenter);
						classGameState.g.DrawEllipse(pHighlight, new Rectangle(ptEditResource.X - intCircleRadius, ptEditResource.Y - intCircleRadius, 2 * intCircleRadius, 2 * intCircleRadius));
						classGameState.picView.Image = classGameState.bmpViewScreen;
					}
					break;

				case enuMode_StructureInteriorEditor.edit_Astronauts:
					if (intPointIndex >= 0 && intPointIndex < cSI_Room.cObjContainer.lcAstronauts.Count)
					{
						Point ptEditAstronaut = classLandscape.getPointScreen(cSI_Room.cObjContainer.lcAstronauts[intPointIndex].cCDO.dptPos, classGameState.dptViewFocus, classGameState.ptScreenCenter);
						classGameState.g.DrawEllipse(pHighlight, new Rectangle(ptEditAstronaut.X - intCircleRadius, ptEditAstronaut.Y - intCircleRadius, 2 * intCircleRadius, 2 * intCircleRadius));
						classGameState.picView.Image = classGameState.bmpViewScreen;
					}
					break;

				case enuMode_StructureInteriorEditor.edit_Ships:
					if (intPointIndex >= 0 && intPointIndex < cSI_Room.cObjContainer.lcShips.Count)
					{
						//HighlightPoint(intPointIndex);
						classGameState.picView.Image = classGameState.bmpViewScreen;
					}
					break;
			}
		}
		#endregion

		#region BoldPoints
		void BoldPoint(int intPointIndex, enuTelePortEdit_PointSelection ePointSelection)
		{
			if (intPointIndex >= 0 && intPointIndex < cSI_Room.cTeleporters.Length)
			{
				switch (ePointSelection)
				{
					case enuTelePortEdit_PointSelection.Pos:
						Point ptEditTeleporter = classLandscape.getPointScreen(cSI_Room.cTeleporters[intPointIndex].dptPos, classGameState.dptViewFocus, classGameState.ptScreenCenter);
						classGameState.g.DrawEllipse(pBold, new Rectangle(ptEditTeleporter.X - intCircleRadius, ptEditTeleporter.Y - intCircleRadius, 2 * intCircleRadius, 2 * intCircleRadius));
						break;

					case enuTelePortEdit_PointSelection.RadArrivingObject:
						classMath.classDoubleCartesian dptArrivingPoint = classMath.convertRadToDCar(cSI_Room.cTeleporters[intPointIndex].dptPos, cSI_Room.cTeleporters[intPointIndex].cRadPlaceArrivingObject);
						Point ptEditTeleporter_Arriving = classLandscape.getPointScreen(dptArrivingPoint, classGameState.dptViewFocus, classGameState.ptScreenCenter);
						classGameState.g.DrawEllipse(pBold, new Rectangle(ptEditTeleporter_Arriving.X - intCircleRadius, ptEditTeleporter_Arriving.Y - intCircleRadius, 2 * intCircleRadius, 2 * intCircleRadius));
						break;

					case enuTelePortEdit_PointSelection.Radius:
						classMath.classDoubleCartesian dptRadius = classMath.convertRadToDCar(cSI_Room.cTeleporters[intPointIndex].dptPos, new classMath.classRadialCoor(5.0 / 4.0 * Math.PI, cSI_Room.cTeleporters[intPointIndex].dblRadius));
						Point ptEditTeleporter_Radius = classLandscape.getPointScreen(dptRadius, classGameState.dptViewFocus, classGameState.ptScreenCenter);
						classGameState.g.DrawEllipse(pBold, new Rectangle(ptEditTeleporter_Radius.X - intCircleRadius, ptEditTeleporter_Radius.Y - intCircleRadius, 2 * intCircleRadius, 2 * intCircleRadius));
						break;

					case enuTelePortEdit_PointSelection.RealWorldHeight:
						classMath.classDoubleCartesian dptRealWorldHeight = cSI_Room.cTeleporters[intPointIndex].dptPos.Copy();
						dptRealWorldHeight.Y -= formMarsMission.ConvertRWUnitsToGWUnits(cSI_Room.cTeleporters[intPointIndex].Coupling.RealWorldHeight / 2);
						Point ptRealworldHeight = classLandscape.getPointScreen(dptRealWorldHeight, classGameState.dptViewFocus, classGameState.ptScreenCenter);
						classGameState.g.DrawEllipse(pBold, new Rectangle(ptRealworldHeight.X - 2, ptRealworldHeight.Y - 2, 4, 4));
						break;
				}
			}
		}

		void BoldPoint(int intPointIndex)
		{
			switch (eMode)
			{
				case enuMode_StructureInteriorEditor.edit_Teleporters:
					if (intPointIndex >= 0 && intPointIndex < cSI_Room.cTeleporters.Length)
					{
						BoldPoint(intPointIndex, eTelePortEdit_PointSelection);
						classGameState.picView.Image = classGameState.bmpViewScreen;
					}
					break;

				case enuMode_StructureInteriorEditor.edit_Resources:
					if (intPointIndex >= 0 && intPointIndex < cSI_Room.cObjContainer.lcResourceObjects.Count)
					{
						Point ptEditResource = classLandscape.getPointScreen(cSI_Room.cObjContainer.lcResourceObjects[intPointIndex].cCDO.dptPos, classGameState.dptViewFocus, classGameState.ptScreenCenter);
						classGameState.g.DrawEllipse(pBold, new Rectangle(ptEditResource.X - intCircleRadius, ptEditResource.Y - intCircleRadius, 2 * intCircleRadius, 2 * intCircleRadius));
						classGameState.picView.Image = classGameState.bmpViewScreen;
					}
					break;

				case enuMode_StructureInteriorEditor.edit_Astronauts:
					if (intPointIndex >= 0 && intPointIndex < cSI_Room.cObjContainer.lcAstronauts.Count)
					{
						Point ptEditAstronaut = classLandscape.getPointScreen(cSI_Room.cObjContainer.lcAstronauts[intPointIndex].cCDO.dptPos, classGameState.dptViewFocus, classGameState.ptScreenCenter);
						classGameState.g.DrawEllipse(pBold, new Rectangle(ptEditAstronaut.X - intCircleRadius, ptEditAstronaut.Y - intCircleRadius, 2 * intCircleRadius, 2 * intCircleRadius));
						classGameState.picView.Image = classGameState.bmpViewScreen;
					}
					break;

				case enuMode_StructureInteriorEditor.edit_Ships:
					if (intPointIndex >= 0 && intPointIndex < cSI_Room.cObjContainer.lcShips.Count)
					{
						//BoldPoint(intPointIndex);
						classGameState.picView.Image = classGameState.bmpViewScreen;
					}
					break;
			}
		}

		void BoldPoint(int intPointIndex, int intPolygonIndex)
		{
			if (intPolygonIndex >= 0 && intPolygonIndex < cSI_Room.cPolygons.Length
				&& intPointIndex >= 0 && intPointIndex < cSI_Room.cPolygons[intPolygonIndex].dptArray.Length)
			{
				Point pt = classLandscape.getPointScreen(cSI_Room.cPolygons[intPolygonIndex].dptArray[intPointIndex], classGameState.dptViewFocus, classGameState.ptScreenCenter);
				classGameState.g.DrawEllipse(pBold, new Rectangle(pt.X - intCircleRadius, pt.Y - intCircleRadius, 2 * intCircleRadius, 2 * intCircleRadius)); 
				classGameState.picView.Image = classGameState.bmpViewScreen;
			}
		}

		
		#endregion


		#endregion

		void formStructureInteriorEditor_SizeChanged(object sender, EventArgs e)
		{
			classGameState.picView.Width = Width - 10;
			classGameState.picView.Left = 0;
			classGameState.picView.Top = 25;
			classGameState.picView.Height = Height - 45;
			classGameState.ptScreenCenter = new Point(classGameState.picView.Width / 2, classGameState.picView.Height / 2);
			formMarsMission.dblAspectRatioYOverX = (double)classGameState.picView.Height / (double)classGameState.picView.Width;
			cmbRooms.Width = (int)((double)Width * .25);
			cmbLocation.Width = (int)((double)Width * .15);
			cmbRooms.Left = 5;
			cmbLocation.Left = cmbRooms.Right+5;
			cmbRooms.Top
				= cmbLocation.Top
				= 25;

			lblZoom.Left = 5;
			lblZoom.Top
				= hsbZoom.Top
				= Height - lblZoom.Height - 45;
			showZoomLabel();
			hsbZoom.Left = lblZoom.Right+5;
			hsbZoom.Width = classGameState.picView.Width - hsbZoom.Left - 10;

			cmbRooms.Visible
				= cmbLocation.Visible
				= lblZoom.Visible
				= hsbZoom.Visible
				= true;
			cmbRooms.BringToFront();
			cmbLocation.BringToFront();
			lblZoom.BringToFront();
			hsbZoom.BringToFront();

		}

		void showZoomLabel()
		{
			lblZoom.Text = formMarsMission.getDistanceString(classGameState.dblZoom);
			lblZoom.Top = hsbZoom.Top;
			lblZoom.Left = hsbZoom.Left - lblZoom.Width;
		}

		private void mnuFile_Exit_Click(object sender, EventArgs e)
		{
			if (bolChangesMadeSinceLastSave && formStructureInteriorEditor.frmStructureInteriorEditor_Main == this)
			{
				if (MessageBox.Show("Changes have been made since you last saved this file.  Would you like to save this file?", "save changes", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
				{
					mnuFile_Save_Click((object)this, new EventArgs());
				}
			}
			gtmrGame.stop();
			Dispose();
		}

		private void mnuFile_Load_Click(object sender, EventArgs e)
		{
			OpenFileDialog ofd = new OpenFileDialog();
			ofd.Filter = "XML Files|StructureInterior*.xml";
			ofd.InitialDirectory = strWorkingDirectory;
			if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
			{
				gtmrGame.stop();
				classGameState.cControlAstronaut = null; bolIgnoreDrawScreen = false;

				classActionSchedule.clearSchedule();
				classAstronaut.cAstronauts = new classAstronaut[0];

				cSI = classStructureInterior.fromXmlFile(ofd.FileName);

				cSI_Room = cSI.cRooms[0];
				cmbLocation.SelectedIndex = (cSI.eLoc == enuLocation.Ship ? 0 : 1);

				rebuildCmbRooms();
				drawScreen();
				eMode = enuMode_StructureInteriorEditor.edit_Structure;

				int intIndexLastBackSlash = ofd.FileName.LastIndexOf("\\");
				if (intIndexLastBackSlash > 0)
				{
					Text = ofd.FileName.Substring(intIndexLastBackSlash + 1).ToUpper().Replace(".XML", "");
				}
				classGameState.dptViewFocus = new classMath.classDoubleCartesian();
			}
		}

		private void setSI(ref classStructureInterior SI)
		{
			cSI = SI;
		}

		static void setDefaultValues(ref classStructureInterior cSI)
		{
			for (int intRoomCounter = 0; intRoomCounter < cSI.cRooms.Length; intRoomCounter++)
			{
				classStructureInterior_Room cRoom = cSI.cRooms[intRoomCounter];
				for (int intAstronautCounter = 0; intAstronautCounter < cRoom.cObjContainer.lcAstronauts.Count; intAstronautCounter++)
				{
					classAstronaut cAstronaut = cRoom.cObjContainer.lcAstronauts[intAstronautCounter];
					cAstronaut.cCDO.intZoom = 7;
					cAstronaut.cCDO.dblCompressionStrength = 205;
				}

				for (int intResCounter = 0; intResCounter < cRoom.cObjContainer.lcResourceObjects.Count; intResCounter++)
				{
					classResourceObject cResource = cRoom.cObjContainer.lcResourceObjects[intResCounter];
					cResource.cCDO.intZoom = 7;
				}

				for (int intShipCounter = 0; intShipCounter < cRoom.cObjContainer.lcShips.Count; intShipCounter++)
				{
					classShip cShip = cRoom.cObjContainer.lcShips[intShipCounter];

					cShip.cCDO.intZoom = 9;
					cShip.cCDO.Thrusters[(int)enuShipThrusters.Main].Setting  = 0.003;
					cShip.MouseMoveControlHeading = true;
					cShip.cCDO.cDampers.V.Setting = 2.0;
					cShip.cCDO.cDampers.H.Setting = 2.0;
					cShip.cCDO.cbolCommands = new CK_Controls.classBoolean[(int)enuShipCommands._numCommands];

					switch (cShip.eModel)
					{
						case enuShipModels.BattleStar:
							cShip.cSI.cEnergyInventory.setEnergy(enuEnergy.eVolt, 100000);
							cShip.cSI.cChemicalInventory.setChemicalInventory("O2", 100000);
							cShip.cSI.cChemicalInventory.setChemicalInventory("H2", 100000);
							cShip.cPropellant = classPropellant.GetPropellant("O2", "H2");	
							break;

						case enuShipModels.DutyCraft:
							cShip.cSI.cEnergyInventory.setEnergy(enuEnergy.eVolt, 30000);
							cShip.cSI.cChemicalInventory.setChemicalInventory("O2", 30000);
							cShip.cSI.cChemicalInventory.setChemicalInventory("H2", 30000);
							cShip.cPropellant = classPropellant.GetPropellant("O2", "H2");	
							break;

						case enuShipModels.Raptor:
							cShip.cSI.cEnergyInventory.setEnergy(enuEnergy.eVolt, 50000);
							cShip.cSI.cChemicalInventory.setChemicalInventory("O2", 50000);
							cShip.cSI.cChemicalInventory.setChemicalInventory("H2", 50000);
							cShip.cPropellant = classPropellant.GetPropellant("O2", "H2");	
							break;

						case enuShipModels.ShuttleCraft:
							cShip.cSI.cEnergyInventory.setEnergy(enuEnergy.eVolt, 10000);
							cShip.cSI.cChemicalInventory.setChemicalInventory("O2", 10000);
							cShip.cSI.cChemicalInventory.setChemicalInventory("H2", 10000);
							cShip.cPropellant = classPropellant.GetPropellant("O2", "H2");	
							break;
					}				

					setDefaultValues(ref cShip.cSI);
				}
			}
			cSI.resetResourceObjectUniqueIDs();
		}

		public class refreshStructureInteriorFiles : Form
		{
			ProgressBar proBar = new ProgressBar();
			Timer tmr = new Timer();
			public refreshStructureInteriorFiles()
			{
				Controls.Add(proBar);
				proBar.Dock = DockStyle.Fill;
				ShowInTaskbar = false;
				FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
				VisibleChanged +=new EventHandler(refreshStructureInteriorFiles_VisibleChanged);
				tmr.Interval = 5;
				tmr.Tick += new EventHandler(tmr_Tick);

				classActionSchedule.clearSchedule();
				if (!classChemistry.Loaded) classChemistry.Load();
				if (classSolarObject.cSolarObjects == null) classSolarObject.initSolarObjects();
				classAction.loadActions();
				classResource.loadResources();
				proBar.Minimum = 0;
				proBar.Value = proBar.Minimum;
				proBar.Maximum = strStructureInteriorFiles.Length;
			}

			string strTempFileName = "tempSI.xml";
			string[] strStructureInteriorFiles = System.IO.Directory.GetFiles(formMarsMission.strWorkingDirectory, "StructureInterior*.xml");
			int intSIFileCounter = 0;

			void tmr_Tick(object sender, EventArgs e)
			{
				tmr.Enabled = false;

				classAstronaut.cAstronauts = new classAstronaut[0];
				// load cSI
				classStructureInterior cSITemp = classStructureInterior.fromXmlFile(strStructureInteriorFiles[intSIFileCounter]);
				if (System.IO.File.Exists(formMarsMission.strWorkingDirectory + strTempFileName)) System.IO.File.Delete(formMarsMission.strWorkingDirectory + strTempFileName);
				System.IO.File.Copy(strStructureInteriorFiles[intSIFileCounter], formMarsMission.strWorkingDirectory + strTempFileName);
				System.IO.File.Delete(strStructureInteriorFiles[intSIFileCounter]);

				try
				{
					// refresh cSI
					setDefaultValues(ref cSITemp);

					// save cSI
					XmlDocument xDoc = new XmlDocument();
					XmlElement xRoot = xDoc.CreateElement("root");
					xDoc.AppendChild(xRoot);

					XmlNode xStructureInterior = cSITemp.getSaveGameNode(ref xDoc);
					xRoot.AppendChild(xStructureInterior);

					xDoc.Save(strStructureInteriorFiles[intSIFileCounter]);
				}
				catch (Exception err)
				{
					MessageBox.Show("an error has occurred : formStructureInteriorEditor.RefreshStructureInteriorFiles() \"" + err.Message.ToString() + "\"", "error");
					System.IO.File.Copy(formMarsMission.strWorkingDirectory + strTempFileName, strStructureInteriorFiles[intSIFileCounter]);
				}

				if (++intSIFileCounter < strStructureInteriorFiles.Length)
				{
					if (proBar.Value < proBar.Maximum) proBar.Value++;
					tmr.Enabled = true;
				}
				else
					Dispose();
			}

			void refreshStructureInteriorFiles_VisibleChanged(object sender, EventArgs e)
			{
				if (Visible)
				{
					Height = 19;
					Width = (int)(Screen.PrimaryScreen.WorkingArea.Width * .75);
					Top = (Screen.PrimaryScreen.WorkingArea.Height - Height) / 2;
					Left = (Screen.PrimaryScreen.WorkingArea.Width - Width) / 2;
					tmr.Enabled = true;
				}
			}

		}

		private void mnuFile_Save_Click(object sender, EventArgs e)
		{
			SaveFileDialog sfd = new SaveFileDialog();
			sfd.Filter = "XML Files|StructureInterior*.xml";
			sfd.InitialDirectory = strWorkingDirectory;
			if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
			{
				setDefaultValues(ref cSI);
				XmlDocument xDoc = new XmlDocument();
				XmlElement xRoot = xDoc.CreateElement("root");
				xDoc.AppendChild(xRoot);

				XmlNode xStructureInterior = cSI.getSaveGameNode(ref xDoc);
				xRoot.AppendChild(xStructureInterior);

				xDoc.Save(sfd.FileName);
				int intIndexLastBackSlash = sfd.FileName.LastIndexOf("\\");
				if (intIndexLastBackSlash > 0)
				{
					Text = sfd.FileName.Substring(intIndexLastBackSlash + 1).ToUpper().Replace(".XML", "");
				}
				bolChangesMadeSinceLastSave = false;
			}
		}

		private void mnuFile_New_Click(object sender, EventArgs e)
		{
			gtmrGame.stop();
			classGameState.cControlAstronaut = null;
			classAstronaut.cAstronauts = new classAstronaut[0];
			cSI = classStructureInterior.fromXmlFile(strWorkingDirectory + "StructureInterior_default.xml");
			cSI_Room = cSI.cRooms[0];
			cSI.cRooms[0].defineWallGrid();
			rebuildCmbRooms();
			classActionSchedule.clearSchedule();
			if (hsbZoom.Value != hsbZoom.Minimum +2)
				hsbZoom.Value = hsbZoom.Minimum +2; // draws screen
			else
				drawScreen();
			eMode = enuMode_StructureInteriorEditor.edit_Structure;
		}

		bool bolIgnoreDrawScreen = false;
		public void drawScreen()
		{
			//Text = intMyUniqueID.ToString();
			if (bolIgnoreDrawScreen) return;
			bolIgnoreDrawScreen = true;
			if (eMode == enuMode_StructureInteriorEditor.Move)
			{
				if (classGameState.cControlAstronaut == null)
				{
					eMode = enuMode_StructureInteriorEditor.edit_Astronauts;
					drawScreen();
					bolIgnoreDrawScreen = false;
					return;
				}
				if (classGameState.cControlAstronaut.cCDO.cSIRoom != cSI_Room)
					cSI_Room = classGameState.cControlAstronaut.cCDO.cSIRoom;
			}

			cSI_Room.Draw(classGameState.dptViewFocus, classGameState.ptScreenCenter);

			if (classGameState.bmpViewScreen == null)
			{
				bolIgnoreDrawScreen = false;
				return;
			}

			//Graphics g = Graphics.FromImage(bmpOutput);
			{
				if (bolView_Teleporters || eMode == enuMode_StructureInteriorEditor.edit_Teleporters)
				{
					for (int intTeleporterCounter = 0; intTeleporterCounter < cSI_Room.cTeleporters.Length; intTeleporterCounter++)
					{
						classTeleporter cTeleporter = cSI_Room.cTeleporters[intTeleporterCounter];
						Point ptCenterTeleporter = classLandscape.getPointScreen(cTeleporter.dptPos, classGameState.dptViewFocus, classGameState.ptScreenCenter);
						double dblTeleporterRadius = (cTeleporter.dblRadius / classGameState.dblZoom);
						classGameState.g.DrawEllipse(classPensAndBrushes.pBlack1, new Rectangle(ptCenterTeleporter.X - 2, ptCenterTeleporter.Y - 2, 4, 4));
						classMath.classDoubleCartesian dptRadius = classMath.convertRadToDCar(cTeleporter.dptPos, new classMath.classRadialCoor(Math.PI * 5.0 / 4.0, cTeleporter.dblRadius));
						Point ptRadius = classLandscape.getPointScreen(dptRadius, classGameState.dptViewFocus);
						classGameState.g.DrawEllipse(classPensAndBrushes.pGray2, new Rectangle(ptRadius.X-4, ptRadius.Y-4, 8,8));
						classGameState.g.DrawEllipse(classPensAndBrushes.pGray1, 
															new Rectangle((int)(ptCenterTeleporter.X - classGameState.dblScreenSizeFactor * cTeleporter.dblRadius), 
																		 (int)(ptCenterTeleporter.Y - classGameState.dblScreenSizeFactor * cTeleporter.dblRadius),
																		 (int)(cTeleporter.dblRadius * classGameState.dblScreenSizeFactor * 2), 
																		 (int)(cTeleporter.dblRadius * classGameState.dblScreenSizeFactor * 2)));

						classMath.classDoubleCartesian dptEndPlaceObjectsArrive = classMath.convertRadToDCar(cTeleporter.dptPos, cTeleporter.cRadPlaceArrivingObject);
						Point ptPlaceObjectsArrive = classLandscape.getPointScreen(dptEndPlaceObjectsArrive, classGameState.dptViewFocus, classGameState.ptScreenCenter);
						classGameState.g.DrawLine(classPensAndBrushes.pRed1, ptCenterTeleporter, ptPlaceObjectsArrive);
						classGameState.g.DrawEllipse(classPensAndBrushes.pRed1, new Rectangle(ptPlaceObjectsArrive.X - 2, ptPlaceObjectsArrive.Y - 2, 4, 4));

						classMath.classDoubleCartesian dptRealWorldHeight = cTeleporter.dptPos.Copy();
						dptRealWorldHeight.Y -= formMarsMission.ConvertRWUnitsToGWUnits(cTeleporter.Coupling.RealWorldHeight / 2);
						Point ptRealworldHeight = classLandscape.getPointScreen(dptRealWorldHeight, classGameState.dptViewFocus, classGameState.ptScreenCenter);
						classGameState.g.DrawEllipse(classPensAndBrushes.pGray1, new Rectangle(ptRealworldHeight.X - 2, ptRealworldHeight.Y - 2, 4, 4));

						PointF ptfDrawString = new PointF(ptCenterTeleporter.X - (int)dblTeleporterRadius, ptCenterTeleporter.Y + (int)dblTeleporterRadius);
						classGameState.g.DrawString(cTeleporter.strName, fntText, classPensAndBrushes.brGreen, ptfDrawString);
					}
				}

				switch (eMode)
				{
					case enuMode_StructureInteriorEditor.edit_Structure:
						for (int intPolygonCounter = 0; intPolygonCounter < cSI_Room.cPolygons.Length; intPolygonCounter++)
						{
							for (int intPointCounter = 0; intPointCounter < cSI_Room.cPolygons[intPolygonCounter].dptArray.Length; intPointCounter++)
							{
								string strText = "Plygn:" + intPolygonCounter.ToString() + ", pt:" + intPointCounter.ToString();
								Point ptText = classLandscape.getPointScreen(cSI_Room.cPolygons[intPolygonCounter].dptArray[intPointCounter], classGameState.dptViewFocus, classGameState.ptScreenCenter);
								PointF ptfText = new PointF(ptText.X + 10, ptText.Y);
								SolidBrush brText = classPensAndBrushes.brGray;
								if (intPointCounter == intIndexPoint_Selected)
								{
									brText = classPensAndBrushes.brRed;
									BoldPoint(intPointCounter, intPolygonCounter);
								}
								else if (intPointCounter == intIndexPoint_NextSelect)
								{
									brText = classPensAndBrushes.brYellow;
									HighlightPoint(intPointCounter, intPolygonCounter);
								}
								else
								{
									DullPoint(intPointCounter, intPolygonCounter);
								}
								classGameState.g.DrawString(strText, fntText, brText, ptfText);
							}
						}
						break;

					case enuMode_StructureInteriorEditor.edit_Teleporters:
						for (int intTeleporterCounter = 0; intTeleporterCounter < cSI_Room.cTeleporters.Length; intTeleporterCounter++)
						{
							classTeleporter cTelePorter = cSI_Room.cTeleporters[intTeleporterCounter];
							if (intTeleporter_Selected == intTeleporterCounter)
							{
								switch (eTelePortEdit_PointSelection)
								{
									case enuTelePortEdit_PointSelection.Pos:
										Point ptPos = classLandscape.getPointScreen(cTelePorter.dptPos, classGameState.dptViewFocus, classGameState.ptScreenCenter);
										classGameState.g.DrawEllipse(pBold, new Rectangle(ptPos.X - intCircleRadius, ptPos.Y - intCircleRadius, 2 * intCircleRadius, 2 * intCircleRadius));
										break;

									case enuTelePortEdit_PointSelection.RadArrivingObject:
										classMath.classDoubleCartesian dptRadArriving = new classMath.classDoubleCartesian(cTelePorter.dptPos.X - cTelePorter.dblRadius, cTelePorter.dptPos.Y - cTelePorter.dblRadius);
										Point ptRadArriving = classLandscape.getPointScreen(dptRadArriving, classGameState.dptViewFocus, classGameState.ptScreenCenter);
										classGameState.g.DrawEllipse(pBold, new Rectangle(ptRadArriving.X - intCircleRadius, ptRadArriving.Y - intCircleRadius, 2 * intCircleRadius, 2 * intCircleRadius));
										break;

									case enuTelePortEdit_PointSelection.Radius:
										classMath.classDoubleCartesian dptRadius = classMath.convertRadToDCar(cSI_Room.cTeleporters[intTeleporter_Selected].dptPos, new classMath.classRadialCoor(5.0 / 4.0 * Math.PI, cSI_Room.cTeleporters[intTeleporter_Selected].dblRadius));
										Point ptRadius = classLandscape.getPointScreen(dptRadius, classGameState.dptViewFocus, classGameState.ptScreenCenter);
										classGameState.g.DrawEllipse(pBold, new Rectangle(ptRadius.X - intCircleRadius, ptRadius.Y - intCircleRadius, 2 * intCircleRadius, 2 * intCircleRadius));
										break;
								}
							}
							else if (intTeleporter_NextSelected == intTeleporterCounter)
							{
								switch (eTelePortEdit_PointSelection)
								{
									case enuTelePortEdit_PointSelection.Pos:
										Point ptPos = classLandscape.getPointScreen(cTelePorter.dptPos, classGameState.dptViewFocus, classGameState.ptScreenCenter);
										classGameState.g.DrawEllipse(pHighlight, new Rectangle(ptPos.X - intCircleRadius, ptPos.Y - intCircleRadius, 2 * intCircleRadius, 2 * intCircleRadius));
										break;

									case enuTelePortEdit_PointSelection.RadArrivingObject:
										classMath.classDoubleCartesian dptRadArriving = new classMath.classDoubleCartesian(cTelePorter.dptPos.X - cTelePorter.dblRadius, cTelePorter.dptPos.Y - cTelePorter.dblRadius);
										Point ptRadArriving = classLandscape.getPointScreen(dptRadArriving, classGameState.dptViewFocus, classGameState.ptScreenCenter);
										classGameState.g.DrawEllipse(pHighlight, new Rectangle(ptRadArriving.X - intCircleRadius, ptRadArriving.Y - intCircleRadius, 2 * intCircleRadius, 2 * intCircleRadius));
										break;

									case enuTelePortEdit_PointSelection.Radius:
										classMath.classDoubleCartesian dptRadius = classMath.convertRadToDCar(cSI_Room.cTeleporters[intTeleporterCounter].dptPos, new classMath.classRadialCoor(5.0 / 4.0 * Math.PI, cSI_Room.cTeleporters[intTeleporterCounter].dblRadius));
										Point ptRadius = classLandscape.getPointScreen(dptRadius, classGameState.dptViewFocus, classGameState.ptScreenCenter);
										classGameState.g.DrawEllipse(pHighlight, new Rectangle(ptRadius.X - intCircleRadius, ptRadius.Y - intCircleRadius, 2 * intCircleRadius, 2 * intCircleRadius));
										break;
								}
							}
							else
							{
								classMath.classDoubleCartesian dptRadius = classMath.convertRadToDCar(cTelePorter.dptPos, cTelePorter.cRadPlaceArrivingObject);
								Point ptRadius = classLandscape.getPointScreen(dptRadius, classGameState.dptViewFocus, classGameState.ptScreenCenter);
								classGameState.g.DrawEllipse(classPensAndBrushes.pBlue1, new Rectangle(ptRadius.X - intCircleRadius, ptRadius.Y - intCircleRadius, 2 * intCircleRadius, 2 * intCircleRadius));
							}
						}
						break;

					case enuMode_StructureInteriorEditor.edit_Ships:
						for (int intShipCounter = 0; intShipCounter < cSI_Room.cObjContainer.lcShips.Count; intShipCounter++)
						{
							classShip cShip = cSI_Room.cObjContainer.lcShips[intShipCounter];
							if (intShip_Selected == intShipCounter)
							{
								Point ptPos = classLandscape.getPointScreen(cShip.cCDO.dptPos, classGameState.dptViewFocus, classGameState.ptScreenCenter);
								classGameState.g.DrawEllipse(pBold, new Rectangle(ptPos.X - intCircleRadius, ptPos.Y - intCircleRadius, 2 * intCircleRadius, 2 * intCircleRadius));

							}
							else if (intShip_NextSelected == intShipCounter)
							{
								Point ptPos = classLandscape.getPointScreen(cShip.cCDO.dptPos, classGameState.dptViewFocus, classGameState.ptScreenCenter);
								classGameState.g.DrawEllipse(pHighlight, new Rectangle(ptPos.X - intCircleRadius, ptPos.Y - intCircleRadius, 2 * intCircleRadius, 2 * intCircleRadius));
							}
							else
							{
								Point ptPos = classLandscape.getPointScreen(cShip.cCDO.dptPos, classGameState.dptViewFocus, classGameState.ptScreenCenter);
								classGameState.g.DrawEllipse(pDull, new Rectangle(ptPos.X - intCircleRadius, ptPos.Y - intCircleRadius, 2 * intCircleRadius, 2 * intCircleRadius));
							}
						}
						break;

					case enuMode_StructureInteriorEditor.edit_Resources:
						for (int intResourceCounter = 0; intResourceCounter < cSI_Room.cObjContainer.lcResourceObjects.Count; intResourceCounter++)
						{
							classResourceObject cResobj = cSI_Room.cObjContainer.lcResourceObjects[intResourceCounter];
							if (intIndexPoint_Selected == intResourceCounter)
							{
								Point ptPos = classLandscape.getPointScreen(cResobj.cCDO.dptPos, classGameState.dptViewFocus, classGameState.ptScreenCenter);
								classGameState.g.DrawEllipse(pBold, new Rectangle(ptPos.X - intCircleRadius, ptPos.Y - intCircleRadius, 2 * intCircleRadius, 2 * intCircleRadius));

							}
							else if (intIndexPoint_NextSelect == intResourceCounter)
							{
								Point ptPos = classLandscape.getPointScreen(cResobj.cCDO.dptPos, classGameState.dptViewFocus, classGameState.ptScreenCenter);
								classGameState.g.DrawEllipse(pHighlight, new Rectangle(ptPos.X - intCircleRadius, ptPos.Y - intCircleRadius, 2 * intCircleRadius, 2 * intCircleRadius));
							}
							else
							{
								Point ptPos = classLandscape.getPointScreen(cResobj.cCDO.dptPos, classGameState.dptViewFocus, classGameState.ptScreenCenter);
								classGameState.g.DrawEllipse(pDull, new Rectangle(ptPos.X - intCircleRadius, ptPos.Y - intCircleRadius, 2 * intCircleRadius, 2 * intCircleRadius));
							}
						}
						break;


					case enuMode_StructureInteriorEditor.edit_Astronauts:
						for (int intAstronautCounter = 0; intAstronautCounter < cSI_Room.cObjContainer.lcAstronauts.Count; intAstronautCounter++)
						{
							classAstronaut cThisAstronaut = cSI_Room.cObjContainer.lcAstronauts[intAstronautCounter];
							if (intIndexPoint_Selected == intAstronautCounter)
							{
								Point ptPos = classLandscape.getPointScreen(cThisAstronaut.cCDO.dptPos, classGameState.dptViewFocus, classGameState.ptScreenCenter);
								classGameState.g.DrawEllipse(pBold, new Rectangle(ptPos.X - intCircleRadius, ptPos.Y - intCircleRadius, 2 * intCircleRadius, 2 * intCircleRadius));

							}
							else if (intIndexPoint_NextSelect == intAstronautCounter)
							{
								Point ptPos = classLandscape.getPointScreen(cThisAstronaut.cCDO.dptPos, classGameState.dptViewFocus, classGameState.ptScreenCenter);
								classGameState.g.DrawEllipse(pHighlight, new Rectangle(ptPos.X - intCircleRadius, ptPos.Y - intCircleRadius, 2 * intCircleRadius, 2 * intCircleRadius));
							}
							else
							{
								Point ptPos = classLandscape.getPointScreen(cThisAstronaut.cCDO.dptPos, classGameState.dptViewFocus, classGameState.ptScreenCenter);
								classGameState.g.DrawEllipse(pDull, new Rectangle(ptPos.X - intCircleRadius, ptPos.Y - intCircleRadius, 2 * intCircleRadius, 2 * intCircleRadius));
							}
						}
						break;
				}

				if (bolViewCDP && classGameState.cControlAstronaut != null && classGameState.cControlAstronaut.cCDO.cCDP.cPoly.Length > 0)
				{
					Point[] ptDrawCDO = new Point[classGameState.cControlAstronaut.cCDO.cCDP.cPoly.Length];

					for (int intPointCounter = 0; intPointCounter < classGameState.cControlAstronaut.cCDO.cCDP.cPoly.Length; intPointCounter++)
					{
						ptDrawCDO[intPointCounter] = classLandscape.getPointScreen(classGameState.cControlAstronaut.cCDO.cCDP.cPoly[intPointCounter], classGameState.dptViewFocus, classGameState.ptScreenCenter);
						classGameState.g.DrawString(intPointCounter.ToString(), fntText, classPensAndBrushes.brRed, new PointF(ptDrawCDO[intPointCounter].X, ptDrawCDO[intPointCounter].Y));
					}
					classGameState.g.DrawPolygon(classPensAndBrushes.pRed1, ptDrawCDO);

					Point ptPolygonCenter = classLandscape.getPointScreen(classGameState.cControlAstronaut.cCDO.dptPos, classGameState.dptViewFocus, classGameState.ptScreenCenter);
					classGameState.g.DrawLine(classPensAndBrushes.pBlack1, ptPolygonCenter.X - 4, ptPolygonCenter.Y, ptPolygonCenter.X + 4, ptPolygonCenter.Y);
					classGameState.g.DrawLine(classPensAndBrushes.pBlack1, ptPolygonCenter.X, ptPolygonCenter.Y - 4, ptPolygonCenter.X, ptPolygonCenter.Y + 4);
				}
			}

			Point ptMouse = classLandscape.getPointScreen(dptMouse, classGameState.dptViewFocus, classGameState.ptScreenCenter);
			classGameState.g.DrawEllipse(classPensAndBrushes.pPurple1, new Rectangle(ptMouse.X - 2, ptMouse.Y - 2, 4, 4));

			classGameState.picView.Image = classGameState.bmpViewScreen;
			bolIgnoreDrawScreen = false;
		}

		private void mnuOptions_ShowZoomBar_Click(object sender, EventArgs e)
		{
			lblZoom.Visible
				= hsbZoom.Visible
				= !lblZoom.Visible;
		}

		private void mnuOptions_ResetResourceUniqueIDs_Click(object sender, EventArgs e) { cSI.resetResourceObjectUniqueIDs(); }

		private void mnuOptions_CenterRooms_Click(object sender, EventArgs e)
		{
			for (int intRoomCounter = 0; intRoomCounter < cSI.cRooms.Length; intRoomCounter++)
			{
				classStructureInterior_Room cSI_thisRoom = cSI.cRooms[intRoomCounter];

				classMath.classDoubleCartesian dptTL = new classMath.classDoubleCartesian(1000000, 1000000);
				classMath.classDoubleCartesian dptBR = new classMath.classDoubleCartesian(-1000000, -1000000);

				for (int intPolygonCounter = 0; intPolygonCounter < cSI_thisRoom.cPolygons.Length; intPolygonCounter++)
				{
					for (int intPointCounter = 0; intPointCounter < cSI_thisRoom.cPolygons[intPolygonCounter].dptArray.Length; intPointCounter++)
					{
						classMath.classDoubleCartesian dpt = cSI_thisRoom.cPolygons[intPolygonCounter].dptArray[intPointCounter];
						if (dpt.X < dptTL.X) dptTL.X = dpt.X;
						if (dpt.Y < dptTL.Y) dptTL.Y = dpt.Y;
						if (dpt.X > dptBR.X) dptBR.X = dpt.X;
						if (dpt.Y > dptBR.Y) dptBR.Y = dpt.Y;
					}
				}

				classMath.classDoubleCartesian dptShift = new classMath.classDoubleCartesian(dptTL.X + (dptBR.X - dptTL.X) / 2, dptTL.Y + (dptBR.Y - dptTL.Y) / 2);

				for (int intPolygonCounter = 0; intPolygonCounter < cSI_thisRoom.cPolygons.Length; intPolygonCounter++)
				{
					for (int intPointCounter = 0; intPointCounter < cSI_thisRoom.cPolygons[intPolygonCounter].dptArray.Length; intPointCounter++)
					{
						classMath.classDoubleCartesian dpt = cSI_thisRoom.cPolygons[intPolygonCounter].dptArray[intPointCounter];
						dpt.X -= dptShift.X;
						dpt.Y -= dptShift.Y;
					}
				}

				for (int intResourceObjectCounter = 0; intResourceObjectCounter < cSI_thisRoom.cObjContainer.lcResourceObjects.Count; intResourceObjectCounter++)
				{
					classResourceObject cRes = cSI_thisRoom.cObjContainer.lcResourceObjects[intResourceObjectCounter];
					cRes.cCDO.dptPos.X -= dptShift.X;
					cRes.cCDO.dptPos.Y -= dptShift.Y;
				}
				
				for (int intAstronautCounter = 0; intAstronautCounter < cSI_thisRoom.cObjContainer.lcAstronauts.Count; intAstronautCounter++)
				{
					classAstronaut cRes = cSI_thisRoom.cObjContainer.lcAstronauts[intAstronautCounter];
					cRes.cCDO.dptPos.X -= dptShift.X;
					cRes.cCDO.dptPos.Y -= dptShift.Y;
				}

				for (int intShipCounter = 0; intShipCounter < cSI_thisRoom.cObjContainer.lcShips.Count; intShipCounter++)
				{
					classShip cRes = cSI_thisRoom.cObjContainer.lcShips[intShipCounter];
					cRes.cCDO.dptPos.X -= dptShift.X;
					cRes.cCDO.dptPos.Y -= dptShift.Y;
				}

				for (int intTeleporterCounter = 0; intTeleporterCounter < cSI_thisRoom.cTeleporters.Length; intTeleporterCounter++)
				{
					classTeleporter cThisTeleporter = cSI_thisRoom.cTeleporters[intTeleporterCounter];
					cThisTeleporter.dptPos.X -= dptShift.X;
					cThisTeleporter.dptPos.Y -= dptShift.Y;
				}
			}
			drawScreen();
		}

		private void mnuOptions_RefreshFiles_Click(object sender, EventArgs e)
		{
			formStructureInteriorEditor.refreshStructureInteriorFiles refreshStructure = new formStructureInteriorEditor.refreshStructureInteriorFiles();

			Hide();
			refreshStructure.ShowDialog();
			Show();

		}

	}

	public class formEdit_StructureInteriorRoom_Name : Form
	{
		CK_Controls.LabelButton lbtnOk = new CK_Controls.LabelButton();
		CK_Controls.LabelButton lbtnCancel = new CK_Controls.LabelButton();
		CK_Controls.TextBox_HighlightChanged txtNewName = new CK_Controls.TextBox_HighlightChanged();
		Label lblOldName = new Label();
		classStructureInterior_Room cSI_Room;

		public formEdit_StructureInteriorRoom_Name(ref classStructureInterior_Room cSIRoom)
		{
			cSI_Room = cSIRoom;

			Controls.Add(lbtnOk);
			Controls.Add(lbtnCancel);
			Controls.Add(txtNewName);
			Controls.Add(lblOldName);

			lbtnOk.Visible
				= lbtnCancel.Visible
				= txtNewName.Visible
				= lblOldName.Visible
				= true;

			FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
			ShowInTaskbar = false;

			txtNewName.Text
				= lblOldName.Text
				= cSI_Room.Name;

			lbtnOk.Text = "Ok";
			lbtnCancel.Text = "Cancel";
			lbtnOk.ClickTogglesFlag
				= lbtnCancel.ClickTogglesFlag
				= false;
			lbtnOk.Click += new EventHandler(lbtnOk_Click);
			lbtnCancel.Click += new EventHandler(lbtnCancel_Click);

			txtNewName.EnterValue += new EventHandler<EventArgs>(txtNewName_EnterValue);

			VisibleChanged += new EventHandler(formEdit_StructureInteriorRoom_Name_VisibleChanged);
		}

		void txtNewName_EnterValue(object sender, EventArgs e)
		{
			lbtnOk_Click((object)lbtnOk, new EventArgs());
			formStructureInteriorEditor.bolChangesMadeSinceLastSave = true;
		}

		void formEdit_StructureInteriorRoom_Name_VisibleChanged(object sender, EventArgs e)
		{
			if (Visible)
			{
				Text = "Edit Room Name";
				lblOldName.Location = new Point(5, 2);
				txtNewName.Location = new Point(lblOldName.Left, lblOldName.Top + lblOldName.Height);
				lblOldName.Width
					= txtNewName.Width
					= 300;

				Width = 2 * lblOldName.Left + lblOldName.Width;

				lbtnOk.Left = Width - lbtnOk.Width - 5;
				lbtnCancel.Left = lbtnOk.Left - lbtnCancel.Width - 5;
				lbtnOk.Top
					= lbtnCancel.Top
					= txtNewName.Top + txtNewName.Height + 5;

				Height = lbtnCancel.Top + lbtnCancel.Height + 25;

				txtNewName.SelectAll();
				txtNewName.Focus();
			}
		}

		void lbtnCancel_Click(object sender, EventArgs e)
		{
			Dispose();
		}

		void lbtnOk_Click(object sender, EventArgs e)
		{
			if (cSI_Room.setName(txtNewName.Text))
				Dispose();
			else
				MessageBox.Show("new name conflicts with name of another room in this structure");
		}
	}

	public class formTeleporterCoupling_Editor : Form
	{
		public classStructureInterior cSI;
		CK_Controls.LabelButton lbtnOk = new CK_Controls.LabelButton();
		CK_Controls.LabelButton lbtnAddCoupling = new CK_Controls.LabelButton();

		Panel pnlTeleporterCouplingFrame = new Panel();
		VScrollBar vsbTeleporterCouplings = new VScrollBar();
		panelTeleporterCoupling_Editor[] pnlTeleporterCouplings = new panelTeleporterCoupling_Editor[0];

		Timer tmrInit = new Timer();

		public formTeleporterCoupling_Editor(ref classStructureInterior cStructureInterior)
		{
			Text = "Edit Teleporters";
			cSI = cStructureInterior;
			ShowInTaskbar = false;

			Controls.Add(lbtnOk);
			lbtnOk.Text = "Ok";
			lbtnOk.ClickTogglesFlag = false;
			lbtnOk.Click += new EventHandler(lbtnOk_Click);

			Controls.Add(lbtnAddCoupling);
			lbtnAddCoupling.Text = "Add Coupling";
			lbtnAddCoupling.ClickTogglesFlag = false;
			lbtnAddCoupling.Click += new EventHandler(lbtnAddCoupling_Click);
			lbtnAddCoupling.Font
				= lbtnOk.Font
				= new System.Drawing.Font("ms sans-serif", 18);
			lbtnAddCoupling.BackgroundDull
				= lbtnOk.BackgroundDull
				= Color.Yellow;

			Controls.Add(pnlTeleporterCouplingFrame); pnlTeleporterCouplingFrame.SendToBack();
			Controls.Add(vsbTeleporterCouplings);
			vsbTeleporterCouplings.Maximum = 1000;

			BackColor = Color.White;

			pnlTeleporterCouplings = new panelTeleporterCoupling_Editor[cSI.cTeleporterCouplings.Length];
			for (int intCouplingCounter = 0; intCouplingCounter < cSI.cTeleporterCouplings.Length; intCouplingCounter++)
			{
				pnlTeleporterCouplings[intCouplingCounter] = new panelTeleporterCoupling_Editor(ref cSI, ref cSI.cTeleporterCouplings[intCouplingCounter]);
				pnlTeleporterCouplingFrame.Controls.Add(pnlTeleporterCouplings[intCouplingCounter]);
				pnlTeleporterCouplings[intCouplingCounter].lbtnDeleteCoupling.Click += new EventHandler(lbtnDeleteCoupling_Click);
				pnlTeleporterCouplings[intCouplingCounter].lbtnDeleteCoupling.Tag = cSI.cTeleporterCouplings[intCouplingCounter];
			}

			tmrInit.Interval = 5;
			tmrInit.Tick += new EventHandler(tmrInit_Tick);
			VisibleChanged += new EventHandler(formTeleporterCoupling_Editor_VisibleChanged);
			vsbTeleporterCouplings.ValueChanged += new EventHandler(vsbTeleporterCouplings_ValueChanged);
			SizeChanged += new EventHandler(formTeleporterCoupling_Editor_SizeChanged);
		}
		bool bolIgnoreSizeChange = false;
		void formTeleporterCoupling_Editor_SizeChanged(object sender, EventArgs e)
		{
			if (bolIgnoreSizeChange) return;
			bolIgnoreSizeChange = true;

			Width = vsbTeleporterCouplings.Left + vsbTeleporterCouplings.Width + 20;
			lbtnAddCoupling.Top
				= lbtnOk.Top
				= Height - lbtnAddCoupling.Height - 40;
			vsbTeleporterCouplings.Height = lbtnAddCoupling.Top - vsbTeleporterCouplings.Top;

			lbtnAddCoupling.Visible
				= lbtnOk.Visible
				= true;
			lbtnOk.Left = vsbTeleporterCouplings.Left - lbtnOk.Width - 5;
			lbtnAddCoupling.Left = lbtnOk.Left - lbtnAddCoupling.Width - 5;
			lbtnAddCoupling.BringToFront();
			lbtnOk.BringToFront();
			placePanelsInsideFrame();
			bolIgnoreSizeChange = false;
		}

		void tmrInit_Tick(object sender, EventArgs e)
		{
			tmrInit.Enabled = false;

			setSizePanels();
			Height = 500;
			pnlTeleporterCouplingFrame.Left = 0;
			pnlTeleporterCouplingFrame.Width = pnlTeleporterCouplings[0].Left + pnlTeleporterCouplings[0].Width;
			vsbTeleporterCouplings.Left = pnlTeleporterCouplingFrame.Left + pnlTeleporterCouplingFrame.Width + 5;
			Width = vsbTeleporterCouplings.Left + vsbTeleporterCouplings.Width + 20;
			vsbTeleporterCouplings.Top = 5;
			lbtnOk.Left = Width - lbtnOk.Width - 5;
			lbtnAddCoupling.Left = lbtnOk.Left - lbtnAddCoupling.Width - 5;
		}

		void lbtnOk_Click(object sender, EventArgs e)
		{
			Dispose();
		}

		void lbtnAddCoupling_Click(object sender, EventArgs e)
		{
			Array.Resize<panelTeleporterCoupling_Editor>(ref pnlTeleporterCouplings, pnlTeleporterCouplings.Length + 1);
			Array.Resize<classTeleporterCoupling>(ref cSI.cTeleporterCouplings, cSI.cTeleporterCouplings.Length + 1);

			cSI.cTeleporterCouplings[cSI.cTeleporterCouplings.Length - 1] = classTeleporterCoupling.New();
			pnlTeleporterCouplings[pnlTeleporterCouplings.Length - 1] = new panelTeleporterCoupling_Editor(ref cSI, ref cSI.cTeleporterCouplings[cSI.cTeleporterCouplings.Length - 1]);
			pnlTeleporterCouplingFrame.Controls.Add(pnlTeleporterCouplings[pnlTeleporterCouplings.Length - 1]);
			pnlTeleporterCouplings[pnlTeleporterCouplings.Length - 1].lbtnDeleteCoupling.Click += new EventHandler(lbtnDeleteCoupling_Click);
			pnlTeleporterCouplings[pnlTeleporterCouplings.Length - 1].lbtnDeleteCoupling.Tag = cSI.cTeleporterCouplings[pnlTeleporterCouplings.Length - 1];
			pnlTeleporterCouplings[pnlTeleporterCouplings.Length - 1].cTeleCoupling.Coupling[0].cSI_Room = cSI.cRooms[0];
			pnlTeleporterCouplings[pnlTeleporterCouplings.Length - 1].cTeleCoupling.Coupling[1].cSI_Room = cSI.cRooms[0];
			setSizePanels();
			placePanelsInsideFrame();
			formStructureInteriorEditor.bolChangesMadeSinceLastSave = true;
		}

		void placePanelsInsideFrame()
		{
			for (int intCouplingCounter = 0; intCouplingCounter < cSI.cTeleporterCouplings.Length; intCouplingCounter++)
			{
				if (intCouplingCounter == 0)
					pnlTeleporterCouplings[intCouplingCounter].Location = new Point(0, 0);
				else
					pnlTeleporterCouplings[intCouplingCounter].Location = new Point(0, pnlTeleporterCouplings[intCouplingCounter - 1].Top + pnlTeleporterCouplings[intCouplingCounter - 1].Height);
			}
			if (pnlTeleporterCouplings.Length > 0)
			{
				pnlTeleporterCouplingFrame.Width = pnlTeleporterCouplings[0].Width;
				pnlTeleporterCouplingFrame.Height = pnlTeleporterCouplings[pnlTeleporterCouplings.Length - 1].Top + pnlTeleporterCouplings[pnlTeleporterCouplings.Length - 1].Height;
			}
			setVsbLargeChange();
		}

		void setSizePanels()
		{
			for (int intPanelCounter = 0; intPanelCounter < pnlTeleporterCouplings.Length; intPanelCounter++)
			{
				pnlTeleporterCouplings[intPanelCounter].placeObjects();
			}
		}

		void formTeleporterCoupling_Editor_VisibleChanged(object sender, EventArgs e)
		{
			if (Visible == true)
			{
				tmrInit.Enabled = true;
			}
		}

		void lbtnDeleteCoupling_Click(object sender, EventArgs e)
		{
			CK_Controls.LabelButton lbtn = (CK_Controls.LabelButton)sender;
			classTeleporterCoupling cTeleCoupling = (classTeleporterCoupling)lbtn.Tag;

			if (MessageBox.Show("delete the teleporter coupling : "
									+ "\r\n" + cTeleCoupling.Coupling[0].strName + " in room " + cTeleCoupling.Coupling[0].cSI_Room.Name
									+ "\r\n" + cTeleCoupling.Coupling[1].strName + " in room " + cTeleCoupling.Coupling[1].cSI_Room.Name,
								"Delete teleporter coupling?",
								MessageBoxButtons.YesNo)
					== DialogResult.Yes)
			{
				for (int intDeleteIndex = 0; intDeleteIndex < cSI.cTeleporterCouplings.Length; intDeleteIndex++)
				{
					if (cTeleCoupling == cSI.cTeleporterCouplings[intDeleteIndex])
					{
						for (int intCouplingCounter = intDeleteIndex; intCouplingCounter < cSI.cTeleporterCouplings.Length - 1; intCouplingCounter++)
						{
							cSI.cTeleporterCouplings[intCouplingCounter] = cSI.cTeleporterCouplings[intCouplingCounter + 1];
							pnlTeleporterCouplings[intCouplingCounter] = pnlTeleporterCouplings[intCouplingCounter + 1];
						}
						Array.Resize<classTeleporterCoupling>(ref cSI.cTeleporterCouplings, cSI.cTeleporterCouplings.Length - 1);
						Array.Resize<panelTeleporterCoupling_Editor>(ref pnlTeleporterCouplings, pnlTeleporterCouplings.Length - 1);
						break;
					}
				}
				placePanelsInsideFrame();
			}
			formStructureInteriorEditor.bolChangesMadeSinceLastSave = true;
		}

		void setVsbLargeChange()
		{
			if (pnlTeleporterCouplingFrame.Height < vsbTeleporterCouplings.Height)
			{
				vsbTeleporterCouplings.Visible = false;
				return;
			}
			vsbTeleporterCouplings.Visible = true;
			vsbTeleporterCouplings.LargeChange = (int)(((double)vsbTeleporterCouplings.Height / (double)pnlTeleporterCouplingFrame.Height) * (double)vsbTeleporterCouplings.Maximum);
		}

		void vsbTeleporterCouplings_ValueChanged(object sender, EventArgs e)
		{
			double dblFraction = (double)vsbTeleporterCouplings.Value / (double)(vsbTeleporterCouplings.Maximum - vsbTeleporterCouplings.LargeChange);
			pnlTeleporterCouplingFrame.Top = -(int)((double)(pnlTeleporterCouplingFrame.Height - vsbTeleporterCouplings.Height) * dblFraction);
		}

	}

	public class panelTeleporterCoupling_Editor : Panel
	{
		public classStructureInterior cSI;
		public classTeleporterCoupling cTeleCoupling;
		public CK_Controls.LabelButton lbtnDeleteCoupling = new CK_Controls.LabelButton();

		Label lbl_A = new Label();
		Label lbl_B = new Label();
		panelTeleporter_Editor pnlTeleporter_A, pnlTeleporter_B;
		ComboBox cmbTeleporterSpriteType = new ComboBox();
		Label lblRealWorldHeight = new Label();
		CK_Controls.TextBox_Numeric ntxtRealWorldHeight = new CK_Controls.TextBox_Numeric();

		public panelTeleporterCoupling_Editor(ref classStructureInterior cStructureInterior, ref classTeleporterCoupling cTeleporterCoupling)
		{
			cSI = cStructureInterior;
			cTeleCoupling = cTeleporterCoupling;

			Controls.Add(lbtnDeleteCoupling);
			lbtnDeleteCoupling.Text = "Delete Coupling";
			lbtnDeleteCoupling.ClickTogglesFlag = false;

			Controls.Add(lbl_A);
			lbl_A.Text = "A:"; lbl_A.AutoSize = true;
			pnlTeleporter_A = new panelTeleporter_Editor(ref cStructureInterior, ref cTeleCoupling.Coupling[0]);
			Controls.Add(pnlTeleporter_A);

			Controls.Add(lbl_B);
			lbl_B.Text = "B:"; lbl_B.AutoSize = true;
			pnlTeleporter_B = new panelTeleporter_Editor(ref cStructureInterior, ref cTeleCoupling.Coupling[1]);
			Controls.Add(pnlTeleporter_B);

			Controls.Add(cmbTeleporterSpriteType);
			for (enuTeleporter_Sprites eTeleporterSpriteCounter = (enuTeleporter_Sprites)0; eTeleporterSpriteCounter < enuTeleporter_Sprites._numTeleporterSprites; eTeleporterSpriteCounter++)
			{
				cmbTeleporterSpriteType.Items.Add(eTeleporterSpriteCounter.ToString());
			}
			cmbTeleporterSpriteType.SelectedIndex = (int)cTeleCoupling.eTeleporterSprite;
			cmbTeleporterSpriteType.Text = cmbTeleporterSpriteType.Items[cmbTeleporterSpriteType.SelectedIndex].ToString();
			cmbTeleporterSpriteType.SelectedIndexChanged += new EventHandler(cmbTeleporterSpriteType_SelectedIndexChanged);

			Controls.Add(lblRealWorldHeight);
			lblRealWorldHeight.Text = "Real World Height : ";
			lblRealWorldHeight.AutoSize = true;

			Controls.Add(ntxtRealWorldHeight);
			ntxtRealWorldHeight.Value = cTeleCoupling.RealWorldHeight;
			ntxtRealWorldHeight.EnterValue += new EventHandler<EventArgs>(ntxtRealWorldHeight_EnterValue);
		}

		void ntxtRealWorldHeight_EnterValue(object sender, EventArgs e)
		{
			cTeleCoupling.RealWorldHeight = ntxtRealWorldHeight.Value;
			formStructureInteriorEditor.bolChangesMadeSinceLastSave = true;
		}

		void cmbTeleporterSpriteType_SelectedIndexChanged(object sender, EventArgs e)
		{
			cTeleCoupling.eTeleporterSprite = (enuTeleporter_Sprites)cmbTeleporterSpriteType.SelectedIndex;
			formStructureInteriorEditor.bolChangesMadeSinceLastSave = true;
		}

		public void placeObjects()
		{
			pnlTeleporter_A.PlaceObjects();
			pnlTeleporter_B.PlaceObjects();

			lbl_A.Top
				= lbl_B.Top
				= pnlTeleporter_A.Top
				= pnlTeleporter_B.Top
				= lbtnDeleteCoupling.Top
				= cmbTeleporterSpriteType.Top
				= 0;

			cmbTeleporterSpriteType.Left = 0;
			lblRealWorldHeight.Left = cmbTeleporterSpriteType.Left;
			ntxtRealWorldHeight.Top
				= lblRealWorldHeight.Top
				= cmbTeleporterSpriteType.Bottom;
			ntxtRealWorldHeight.Left = lblRealWorldHeight.Right;
			ntxtRealWorldHeight.Width = 50;

			cmbTeleporterSpriteType.Width = ntxtRealWorldHeight.Right;

			lbl_A.Left = cmbTeleporterSpriteType.Right + 5; ;
			pnlTeleporter_A.Left = lbl_A.Right;


			lbl_B.Left = pnlTeleporter_A.Right + 5;
			pnlTeleporter_B.Left = lbl_B.Right;

			lbtnDeleteCoupling.Left = pnlTeleporter_B.Right + 5;

			Width = lbtnDeleteCoupling.Right + 10;
			Height = pnlTeleporter_B.Bottom;
			BackColor = Color.White;
		}
	}

	public class panelTeleporter_Editor : Panel
	{
		public classStructureInterior cSI;
		public classTeleporter cTeleporter;

		CK_Controls.TextBox_HighlightChanged txtName = new CK_Controls.TextBox_HighlightChanged();
		ComboBox cmbRoom = new ComboBox();

		public panelTeleporter_Editor(ref classStructureInterior cStructureInterior, ref classTeleporter Teleporter)
		{
			cSI = cStructureInterior;
			cTeleporter = Teleporter;
			if (cTeleporter.strName == null) cTeleporter.strName = "teleporter";

			Controls.Add(txtName);
			txtName.Text = cTeleporter.strName;

			Controls.Add(cmbRoom);
			cmbRoom.Items.Clear();
			for (int intRoomCounter = 0; intRoomCounter < cSI.cRooms.Length; intRoomCounter++)
			{
				cmbRoom.Items.Add(cSI.cRooms[intRoomCounter].Name);
			}
			cmbRoom.Items.Add("-egress-");
			if (cTeleporter.intSI_RoomIndex >= 0)
			{
				cmbRoom.SelectedIndex = cTeleporter.intSI_RoomIndex;
			}
			else
				cmbRoom.SelectedIndex = cmbRoom.Items.Count - 1;
			cmbRoom.Text = cmbRoom.Items[cmbRoom.SelectedIndex].ToString();
			cmbRoom.SelectedIndexChanged += new EventHandler(cmbRoom_SelectedIndexChanged);

			if (cTeleporter.cSI_Room == null)
				cTeleporter.cSI_Room = cSI.cRooms[0];

			txtName.EnterValue += new EventHandler<EventArgs>(txtName_EnterValue);

			BackColor = Color.White;
		}

		void txtName_EnterValue(object sender, EventArgs e)
		{
			cTeleporter.strName = txtName.Text;
			formStructureInteriorEditor.bolChangesMadeSinceLastSave = true;
		}

		
		void cmbRoom_SelectedIndexChanged(object sender, EventArgs e)
		{
			cTeleporter.intSI_RoomIndex = cmbRoom.SelectedIndex;
			formStructureInteriorEditor.bolChangesMadeSinceLastSave = true;
		}

		public void PlaceObjects()
		{
			txtName.Width = 250;
			txtName.Location = new Point(0, 0);
			cmbRoom.Width = txtName.Width;
			cmbRoom.Location = new Point(txtName.Left, txtName.Bottom);

			Width = cmbRoom.Left + cmbRoom.Width + 5;
			Height = cmbRoom.Top + cmbRoom.Height + 5;
		}
	}

	public class formAddResource : Form
	{
		CK_Controls.LabelButton lbtnOk = new CK_Controls.LabelButton();
		CK_Controls.LabelButton lbtnCancel = new CK_Controls.LabelButton();
		ComboBox cmbResources = new ComboBox();
		Label lblQuantity = new Label();
		CK_Controls.TextBox_Numeric ntxtQuantity = new CK_Controls.TextBox_Numeric();
		public int intQuantity = 1;

		public classResourceObject cResObject;

		public formAddResource()
		{
			FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
			Text = "Add resources";

			Controls.Add(lbtnOk);
			lbtnOk.Text = "Ok";

			Controls.Add(lbtnCancel);
			lbtnCancel.Text = "Cancel";

			lbtnOk.ClickTogglesFlag
				= lbtnCancel.ClickTogglesFlag
				= false;

			Controls.Add(lblQuantity);
			lblQuantity.Text = "Quantity:";
			lblQuantity.AutoSize = true;

			Controls.Add(ntxtQuantity);
			ntxtQuantity.Value = (double)intQuantity;

			Controls.Add(cmbResources);
			for (enuResources eResourceCounter = (enuResources)0; eResourceCounter < enuResources._numResources; eResourceCounter++)
				cmbResources.Items.Add(eResourceCounter);

			VisibleChanged += new EventHandler(formAddResource_VisibleChanged);
			lbtnOk.Click += new EventHandler(lbtnOk_Click);
			lbtnCancel.Click += new EventHandler(lbtnCancel_Click);
		}

		void lbtnCancel_Click(object sender, EventArgs e)
		{
			Dispose();
		}

		void lbtnOk_Click(object sender, EventArgs e)
		{
			cResObject = null;
			enuResources eResource = (enuResources)cmbResources.SelectedIndex;
			if (eResource >= (enuResources)0 && eResource < enuResources._numResources)
			{
				cResObject = new classResourceObject();
				cResObject.eResource = (enuResources)cmbResources.SelectedIndex;
				intQuantity = (int)ntxtQuantity.Value;
				formStructureInteriorEditor.bolChangesMadeSinceLastSave = true;
			}
			Dispose();
		}

		void formAddResource_VisibleChanged(object sender, EventArgs e)
		{
			if (Visible)
			{
				cmbResources.Left = 5;
				cmbResources.Width = 300;
				cmbResources.Top = 5;

				lblQuantity.Top
					= ntxtQuantity.Top
					= cmbResources.Bottom + 5;

				lblQuantity.Left = 5;
				ntxtQuantity.Left = lblQuantity.Right;

				lbtnOk.Top
					= lbtnCancel.Top
					= ntxtQuantity.Bottom + 5;

				lbtnCancel.Left = cmbResources.Right - lbtnCancel.Width;
				lbtnOk.Left = lbtnCancel.Left - lbtnOk.Width - 5;

				Height = lbtnCancel.Bottom + 25;
				Width = lbtnCancel.Right + 10;
			}
		}
	}

	public class formAstronaut_Edit : Form
	{
		Label lblName = new Label();
		CK_Controls.TextBox_HighlightChanged txtName = new CK_Controls.TextBox_HighlightChanged();
		Button btnOk = new Button();
		Label lblHeight = new Label();
		CK_Controls.TextBox_Numeric txtnHeight = new CK_Controls.TextBox_Numeric();

		panelProficiencyEdit[] pnlProficiencies = new panelProficiencyEdit[(int)enuAstronautProficiencies._numAstronautProficiencies];

		public class panelProficiencyEdit : Panel
		{
			CK_Controls.TextBox_Numeric ntxtRating = new CK_Controls.TextBox_Numeric();
			CK_Controls.TextBox_Numeric ntxtExperience = new CK_Controls.TextBox_Numeric();
			public Label lblName = new Label();

			classAstronautProficiency cProficiency;
			public panelProficiencyEdit(ref classAstronautProficiency Proficiency)
			{
				cProficiency = Proficiency;

				Controls.Add(lblName);
				Controls.Add(ntxtRating);
				Controls.Add(ntxtExperience);

				lblName.AutoSize = false;
				lblName.Width = 80;
				ntxtExperience.Width
					= ntxtRating.Width
					= 50;

				lblName.Location = new Point();
				ntxtRating.Location = new Point(lblName.Right, lblName.Top);
				ntxtExperience.Location = new Point(ntxtRating.Right, lblName.Top);

				ntxtRating.Value = cProficiency.Rating;
				ntxtExperience.Value = cProficiency.Experience;

				ntxtRating.EnterValue += new EventHandler<EventArgs>(ntxtRating_EnterValue);
				ntxtExperience.EnterValue += new EventHandler<EventArgs>(ntxtExperience_EnterValue);
				Width = ntxtExperience.Right;
				Height = ntxtExperience.Height;
			}

			void ntxtExperience_EnterValue(object sender, EventArgs e)
			{
				cProficiency.Experience = ntxtExperience.Value;
				formStructureInteriorEditor.bolChangesMadeSinceLastSave = true;
			}

			void ntxtRating_EnterValue(object sender, EventArgs e)
			{
				cProficiency.Rating = ntxtRating.Value;
				formStructureInteriorEditor.bolChangesMadeSinceLastSave = true;
			}
		}

		classAstronaut cAstronaut;
		public formAstronaut_Edit(ref classAstronaut Astronaut)
		{
			cAstronaut = Astronaut;

			Controls.Add(lblName);
			Controls.Add(txtName);
			Controls.Add(txtnHeight);
			Controls.Add(lblHeight);
			txtName.EnterValue += new EventHandler<EventArgs>(txtName_EnterValue);
			txtnHeight.EnterValue += new EventHandler<EventArgs>(txtnHeight_EnterValue);

			for (enuAstronautProficiencies eProficiencyCounter = (enuAstronautProficiencies)0; eProficiencyCounter < enuAstronautProficiencies._numAstronautProficiencies; eProficiencyCounter++)
			{
				pnlProficiencies[(int)eProficiencyCounter] = new panelProficiencyEdit(ref cAstronaut.cProficiencies[(int)eProficiencyCounter]);
				pnlProficiencies[(int)eProficiencyCounter].lblName.Text = eProficiencyCounter.ToString();
				Controls.Add(pnlProficiencies[(int)eProficiencyCounter]);
			}

			Controls.Add(btnOk);
			btnOk.Text = "Ok";
			btnOk.Click += new EventHandler(btnOk_Click);

			VisibleChanged += new EventHandler(formAstronaut_Edit_VisibleChanged);

		}

		void txtnHeight_EnterValue(object sender, EventArgs e)
		{
			cAstronaut.cCDO.RealWorldHeight = txtnHeight.Value;
			cAstronaut.cCDO.radius = formMarsMission.ConvertRWUnitsToGWUnits(cAstronaut.cCDO.RealWorldHeight) / 2;
			Sprite.classBmpAndPtTLInfo cBmp = classAstronaut.cSprAstronaut_Complete.getImageOnBitmap(0, 0, 0, 1.0, Sprite.enuMirror.none, false);
			cAstronaut.dblDrawSizeFactor = formMarsMission.getDrawSizeFactor(cAstronaut.cCDO.RealWorldHeight, cBmp.bmp);
			formStructureInteriorEditor.frmStructureInteriorEditor_Current.drawScreen();
			formStructureInteriorEditor.bolChangesMadeSinceLastSave = true;
		}

		void txtName_EnterValue(object sender, EventArgs e)
		{
			if (formStructureInteriorEditor.AstronautNameExists(txtName.Text))
				txtName.Text = cAstronaut.Name;
			else
				cAstronaut.Name = txtName.Text;
			formStructureInteriorEditor.bolChangesMadeSinceLastSave = true;
		}

		void btnOk_Click(object sender, EventArgs e)
		{
			formStructureInteriorEditor.frmStructureInteriorEditor_Current.drawScreen();
			Close();
		}

		void formAstronaut_Edit_VisibleChanged(object sender, EventArgs e)
		{
			if (Visible)
			{
				lblName.Text = "name";
				lblName.AutoSize = true;
				lblName.Width = 150;
				lblName.Left = 5;
				lblName.Top = 5;
				txtName.Left = lblName.Right;
				txtName.Top = lblName.Top;
				txtName.Text = cAstronaut.Name;

				lblHeight.Text = "Height";
				lblHeight.Left = lblName.Left;
				lblHeight.AutoSize = true;
				lblHeight.Width = 150;
				lblHeight.Left = 5;
				lblHeight.Top = txtnHeight.Bottom + 5;
				txtnHeight.Left = lblHeight.Right;
				txtnHeight.Top = lblHeight.Top;
				txtnHeight.Value = cAstronaut.cCDO.RealWorldHeight;

				for (enuAstronautProficiencies eProficiencyCounter = (enuAstronautProficiencies)0; eProficiencyCounter < enuAstronautProficiencies._numAstronautProficiencies; eProficiencyCounter++)
				{
					pnlProficiencies[(int)eProficiencyCounter].Left = 5;
					pnlProficiencies[(int)eProficiencyCounter].Top = txtnHeight.Bottom + (int)eProficiencyCounter * pnlProficiencies[0].Height;
				}

				Width = pnlProficiencies[0].Right + 20;
				txtName.Width = pnlProficiencies[0].Right - txtName.Left;
				txtnHeight.Width = pnlProficiencies[0].Right - txtnHeight.Left;

				btnOk.Left = Width - btnOk.Width - 20;
				btnOk.Top = pnlProficiencies[(int)enuAstronautProficiencies._numAstronautProficiencies - 1].Bottom;

				Height = btnOk.Bottom + 35;
			}
		}
	}

	public class formShip_EditName : Form
	{
		CK_Controls.TextBox_HighlightChanged txthlName = new CK_Controls.TextBox_HighlightChanged();
		Label lblName = new Label();
		Button btnOk = new Button();
		Button btnCancel = new Button();
		classShip cShip;
		public formShip_EditName(ref classShip Ship)
		{
			cShip = Ship;
			Controls.Add(txthlName); txthlName.Text = cShip.Name;
			Controls.Add(lblName); lblName.Text = "Name"; lblName.AutoSize = true;
			Controls.Add(btnOk); btnOk.Text = "ok";
			Controls.Add(btnCancel); btnCancel.Text = "cancel";
			SizeChanged += new EventHandler(formShip_EditName_SizeChanged);
			VisibleChanged += new EventHandler(formShip_EditName_VisibleChanged);
			btnOk.Click += new EventHandler(btnOk_Click);
			btnCancel.Click += new EventHandler(btnCancel_Click);
			BackColor = Color.White;
			Text = "Edit Ship Name";
		}

		void btnCancel_Click(object sender, EventArgs e)
		{
			Dispose();
		}

		void btnOk_Click(object sender, EventArgs e)
		{
			cShip.Name = txthlName.Text;
			Dispose();
		}

		void formShip_EditName_SizeChanged(object sender, EventArgs e) { placeObjects(); }
		void formShip_EditName_VisibleChanged(object sender, EventArgs e) 
		{
			if (Visible)
			{
				Height = 120;
			}
		}

		void placeObjects()
		{
			lblName.Location = new Point(5, 5);
			txthlName.Location = new Point(lblName.Right, lblName.Top);
			txthlName.Width = Width - txthlName.Left - 20;
			btnOk.Left = Width - btnOk.Width - 20;
			btnCancel.Left = btnOk.Left - btnCancel.Width - 5;
			btnOk.Top
				= btnCancel.Top
				= Height - btnCancel.Height - 45;
		}
	}

	public class formSelectNewShipModel : Form
	{
		ComboBox cmbModels = new ComboBox();
		public enuShipModels eModel = enuShipModels.Raptor;
		public formSelectNewShipModel()
		{
			cmbModels.Items.Clear();
			for (enuShipModels eModelCounter = (enuShipModels)0; eModelCounter < enuShipModels._numShipModels; eModelCounter++)
			{
				cmbModels.Items.Add(eModelCounter.ToString());
			}
			cmbModels.SelectedIndex = 0;
			Controls.Add(cmbModels);
			cmbModels.Dock = DockStyle.Fill;
			FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;

			VisibleChanged += new EventHandler(formSelectNewShipModel_VisibleChanged);
			cmbModels.SelectedIndexChanged += new EventHandler(cmbModels_SelectedIndexChanged);
		}

		void cmbModels_SelectedIndexChanged(object sender, EventArgs e)
		{
			eModel = (enuShipModels)cmbModels.SelectedIndex;
			Dispose();
		}

		void formSelectNewShipModel_VisibleChanged(object sender, EventArgs e)
		{
			cmbModels.Location = new Point();
			Height = 18;
			Width = 100;
			Location = new Point(Control.MousePosition.X, Control.MousePosition.Y);
			if (Right > Screen.PrimaryScreen.WorkingArea.Width)
				Left = Screen.PrimaryScreen.WorkingArea.Width - Width;
			if (Bottom > Screen.PrimaryScreen.WorkingArea.Height)
				Top = Screen.PrimaryScreen.WorkingArea.Height - Height;
		}
	}

	
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
CEO unemployable
Canada Canada
Christ Kennedy grew up in the suburbs of Montreal and is a bilingual Quebecois with a bachelor’s degree in computer engineering from McGill University. He is unemployable and currently living in Moncton, N.B. writing his next novel.

Comments and Discussions