public void Finish() { if ( !Started ) { Debugger.Break(); return; } var A = 0; var UnitAdd = new clsUnitAdd(); var Unit = default(clsUnit); UnitAdd.Map = Map; UnitAdd.StoreChange = true; for ( A = 0; A <= OldUnitCount - 1; A++ ) { Unit = OldUnits[A]; NewAltitude = (int)(Map.GetTerrainHeight(Unit.Pos.Horizontal)); if ( NewAltitude != Unit.Pos.Altitude ) { NewUnit = new clsUnit(Unit, Map); ID = Unit.ID; //NewUnit.Pos.Altitude = NewAltitude //these create changed sectors and must be done before drawing the new sectors Map.UnitRemoveStoreChange(Unit.MapLink.ArrayPosition); UnitAdd.NewUnit = NewUnit; UnitAdd.ID = ID; UnitAdd.Perform(); App.ErrorIDChange(ID, NewUnit, "UpdateSectorUnitHeights"); } } Started = false; }
private void ProcessUnitReceived(clsUnit unit, Topic command, string payload) { if (command == Topic.command && Enum.TryParse(payload, true, out UnitCommands cmd)) { if (string.Compare(unit.ToState(), cmd.ToString()) != 0) { log.Debug("SetUnit: {id} to {value}", unit.Number, cmd.ToString()); OmniLink.SendCommand(UnitMapping[cmd], 0, (ushort)unit.Number); } } else if (command == Topic.brightness_command && int.TryParse(payload, out int unitValue)) { log.Debug("SetUnit: {id} to {value}%", unit.Number, payload); OmniLink.SendCommand(enuUnitCommand.Level, BitConverter.GetBytes(unitValue)[0], (ushort)unit.Number); // Force status change instead of waiting on controller to update // Home Assistant sends brightness immediately followed by ON, // which will cause light to go to 100% brightness unit.Status = (byte)(100 + unitValue); } else if (command == Topic.scene_command && char.TryParse(payload, out char scene)) { log.Debug("SetUnit: {id} to {value}", unit.Number, payload); OmniLink.SendCommand(enuUnitCommand.Compose, (byte)(scene - 63), (ushort)unit.Number); } }
public comDestroyUnit(clsUnit Unit, Player owner, Field FieldField) : base("DestroyUnit") { this.m_objUnitToCommand = Unit; this.m_Owner = owner; this.m_FieldField = FieldField; }
public comPlaceUnit(clsUnit Unit, Player owner, clsUnitType UnitTypeToPlace) : base("PlaceUnit") { this.m_objUnitToCommand = Unit; this.m_Owner = owner; this.m_UnitTypeToPlace = UnitTypeToPlace; }
private void ProcessUnitReceived(clsUnit unit, string command, string payload) { if (string.Compare(command, Topic.command.ToString()) == 0 && (payload == "ON" || payload == "OFF")) { if (unit.ToState() != payload) { log.Debug("SetUnit: " + unit.Number + " to " + payload); if (payload == "ON") { OmniLink.Controller.SendCommand(enuUnitCommand.On, 0, (ushort)unit.Number); } else { OmniLink.Controller.SendCommand(enuUnitCommand.Off, 0, (ushort)unit.Number); } } } else if (string.Compare(command, Topic.brightness_command.ToString()) == 0 && Int32.TryParse(payload, out int unitValue)) { log.Debug("SetUnit: " + unit.Number + " to " + payload + "%"); OmniLink.Controller.SendCommand(enuUnitCommand.Level, BitConverter.GetBytes(unitValue)[0], (ushort)unit.Number); // Force status change instead of waiting on controller to update // Home Assistant sends brightness immediately followed by ON, // which will cause light to go to 100% brightness unit.Status = (byte)(100 + unitValue); } }
private void PublishUnits() { log.Debug("Publishing units"); for (ushort i = 1; i < OmniLink.Controller.Units.Count; i++) { clsUnit unit = OmniLink.Controller.Units[i]; if (unit.DefaultProperties == true || Global.mqtt_discovery_ignore_units.Contains(unit.Number)) { string type = i < 385 ? "light" : "switch"; MqttClient.PublishAsync($"{Global.mqtt_discovery_prefix}/{type}/{Global.mqtt_prefix}/unit{i.ToString()}/config", null, MqttQualityOfServiceLevel.AtMostOnce, true); continue; } PublishUnitState(unit); if (i < 385) { MqttClient.PublishAsync($"{Global.mqtt_discovery_prefix}/light/{Global.mqtt_prefix}/unit{i.ToString()}/config", JsonConvert.SerializeObject(unit.ToConfig()), MqttQualityOfServiceLevel.AtMostOnce, true); } else { MqttClient.PublishAsync($"{Global.mqtt_discovery_prefix}/switch/{Global.mqtt_prefix}/unit{i.ToString()}/config", JsonConvert.SerializeObject(unit.ToConfigSwitch()), MqttQualityOfServiceLevel.AtMostOnce, true); } } }
public clsUnit Perform() { if ( AutoWalls ) { if ( ObjectTypeBase.Type == UnitType.PlayerStructure ) { var structureTypeBase = (StructureTypeBase)ObjectTypeBase; if ( structureTypeBase.WallLink.IsConnected ) { clsWallType AutoWallType = null; AutoWallType = structureTypeBase.WallLink.Source; Map.PerformTileWall(AutoWallType, Map.GetPosTileNum(Horizontal), true); return null; } } } var newUnit = new clsUnit(); if ( RandomizeRotation ) { newUnit.Rotation = (int)(App.Random.Next() * 360.0D); } else { newUnit.Rotation = Rotation; } newUnit.UnitGroup = UnitGroup; newUnit.Pos = Map.TileAlignedPosFromMapPos(Horizontal, ObjectTypeBase.get_GetFootprintSelected(newUnit.Rotation)); newUnit.TypeBase = ObjectTypeBase; var UnitAdd = new clsUnitAdd(); UnitAdd.Map = Map; UnitAdd.NewUnit = newUnit; UnitAdd.StoreChange = true; UnitAdd.Perform(); return newUnit; }
public static Switch ToConfigSwitch(this clsUnit unit) { Switch ret = new Switch(); ret.name = Global.mqtt_discovery_name_prefix + unit.Name; ret.state_topic = unit.ToTopic(Topic.state); ret.command_topic = unit.ToTopic(Topic.command); return(ret); }
public facPlaceUnitFactory(clsUnit u, Field FieldField) : base(u, FieldField) { //set Members m_Unit = u; //Init Stuff m_originSektor = FieldField.getSektorForUnit(u); }
private void PublishUnitState(clsUnit unit) { PublishAsync(unit.ToTopic(Topic.state), unit.ToState()); if (unit.Number < 385) { PublishAsync(unit.ToTopic(Topic.brightness_state), unit.ToBrightnessState().ToString()); } }
private void PublishUnitState(clsUnit unit) { MqttClient.PublishAsync(unit.ToTopic(Topic.state), unit.ToState(), MqttQualityOfServiceLevel.AtMostOnce, true); if (unit.Number < 385) { MqttClient.PublishAsync(unit.ToTopic(Topic.brightness_state), unit.ToBrightnessState().ToString(), MqttQualityOfServiceLevel.AtMostOnce, true); } }
public facSolveKollision(clsUnit u, Field FieldField) : base(u, FieldField) { //set Members m_Unit = u; //Init Stuff m_originSektor = FieldField.getSektorForUnit(u); }
public static Switch ToConfigSwitch(this clsUnit unit) { Switch ret = new Switch(); ret.unique_id = $"{Global.mqtt_prefix}unit{unit.Number.ToString()}switch"; ret.name = Global.mqtt_discovery_name_prefix + unit.Name; ret.state_topic = unit.ToTopic(Topic.state); ret.command_topic = unit.ToTopic(Topic.command); return(ret); }
public facMoveFactory(clsUnit u, Field FieldField) : base(u, FieldField) { //set Members m_Unit = u; //Init Stuff m_originSektor = FieldField.getSektorForUnit(u); m_listKnownMovements.Add(m_originSektor.strUniqueID); }
public static Light ToConfig(this clsUnit unit) { Light ret = new Light(); ret.name = Global.mqtt_discovery_name_prefix + unit.Name; ret.state_topic = unit.ToTopic(Topic.state); ret.command_topic = unit.ToTopic(Topic.command); ret.brightness_state_topic = unit.ToTopic(Topic.brightness_state); ret.brightness_command_topic = unit.ToTopic(Topic.brightness_command); return(ret); }
public static Light ToConfig(this clsUnit unit) { Light ret = new Light(); ret.unique_id = $"{Global.mqtt_prefix}unit{unit.Number.ToString()}light"; ret.name = Global.mqtt_discovery_name_prefix + unit.Name; ret.state_topic = unit.ToTopic(Topic.state); ret.command_topic = unit.ToTopic(Topic.command); ret.brightness_state_topic = unit.ToTopic(Topic.brightness_state); ret.brightness_command_topic = unit.ToTopic(Topic.brightness_command); return(ret); }
public UnitContract GetUnit(ushort id) { Event.WriteVerbose("WebService", "GetUnit: " + id); WebOperationContext ctx = WebOperationContext.Current; ctx.OutgoingResponse.Headers.Add("type", "unit"); clsUnit unit = WebService.HAC.Units[id]; return(Helper.ConvertUnit(id, unit)); }
private void btnUnitSelect_Click(object sender, EventArgs e) { frmUnitsLookUp lookup = new frmUnitsLookUp(); lookup.strProject = cmbProjects.Text; lookup.strBlock = cmbSector.Text; lookup.strSizeCode = cmbSizeCode.Text; if (lookup.ShowDialog() == System.Windows.Forms.DialogResult.OK) { txtUnit.Text = lookup.strunitID; clsUnit unit = da.GetUnitByUnitID(txtUnit.Text); if (unit == null) { return; } decimal decPlotPrice = 0, decPlotCharges = 0, decPlotChargesPerc = 0; decPlotPrice = unit.decPrice; txtPlotPrice.Text = decPlotPrice.ToString("N2"); txtUnitType.Text = unit.strUnitTypeID; txtUnitCategory.Text = unit.strUnitCategoryID; if (unit.strUnitTypeID == "GENERAL") { txtChargesPercentage.Text = 0.ToString("N2"); } else if (unit.strUnitTypeID == "PARK FACE" || unit.strUnitTypeID == "WIDE ROAD" || unit.strUnitTypeID == "CORNER") { decPlotChargesPerc = 10; txtChargesPercentage.Text = 10.ToString("N2"); } else if (unit.strUnitTypeID == "P. F. CORNER" || unit.strUnitTypeID == "WIDE ROAD +PARK FACE" || unit.strUnitTypeID == "WD.ROAD+CORNER") { decPlotChargesPerc = 20; txtChargesPercentage.Text = 20.ToString("N2"); } txtPlotPrice.Text = decPlotPrice.ToString("N2"); decPlotCharges = decPlotPrice * decPlotChargesPerc / 100; txtPlotTypeCharges.Text = decPlotCharges.ToString("N2"); txtTotalPrice.Text = (decPlotPrice + decPlotCharges).ToString("N2"); SetNetPrice(); } }
public static int ToBrightnessState(this clsUnit unit) { if (unit.Status > 100) { return((ushort)(unit.Status - 100)); } else if (unit.Status == 1) { return(100); } else { return(0); } }
public void DrawUnitRectangle(clsUnit Unit, int BorderInsideThickness, sRGBA_sng InsideColour, sRGBA_sng OutsideColour) { sXY_int PosA = new sXY_int(); sXY_int PosB = new sXY_int(); int A = 0; int Altitude = Unit.Pos.Altitude - ViewInfo.ViewPos.Y; GetFootprintTileRangeClamped(Unit.Pos.Horizontal, Unit.Type.get_GetFootprintSelected(Unit.Rotation), PosA, PosB); A = PosA.Y; PosA.X = (int)((PosA.X + 0.125D) * App.TerrainGridSpacing - ViewInfo.ViewPos.X); PosA.Y = (int)((PosB.Y + 0.875D) * - App.TerrainGridSpacing - ViewInfo.ViewPos.Z); PosB.X = (int)((PosB.X + 0.875D) * App.TerrainGridSpacing - ViewInfo.ViewPos.X); PosB.Y = (int)((A + 0.125D) * - App.TerrainGridSpacing - ViewInfo.ViewPos.Z); GL.Color4(OutsideColour.Red, OutsideColour.Green, OutsideColour.Blue, OutsideColour.Alpha); GL.Vertex3(PosB.X, Altitude, Convert.ToInt32(- PosA.Y)); GL.Vertex3(PosA.X, Altitude, Convert.ToInt32(- PosA.Y)); GL.Color4(InsideColour.Red, InsideColour.Green, InsideColour.Blue, InsideColour.Alpha); GL.Vertex3(PosA.X + BorderInsideThickness, Altitude, Convert.ToInt32(- (PosA.Y + BorderInsideThickness))); GL.Vertex3(PosB.X - BorderInsideThickness, Altitude, Convert.ToInt32(- (PosA.Y + BorderInsideThickness))); GL.Color4(OutsideColour.Red, OutsideColour.Green, OutsideColour.Blue, OutsideColour.Alpha); GL.Vertex3(PosA.X, Altitude, Convert.ToInt32(- PosA.Y)); GL.Vertex3(PosA.X, Altitude, Convert.ToInt32(- PosB.Y)); GL.Color4(InsideColour.Red, InsideColour.Green, InsideColour.Blue, InsideColour.Alpha); GL.Vertex3(PosA.X + BorderInsideThickness, Altitude, Convert.ToInt32(- (PosB.Y - BorderInsideThickness))); GL.Vertex3(PosA.X + BorderInsideThickness, Altitude, Convert.ToInt32(- (PosA.Y + BorderInsideThickness))); GL.Color4(OutsideColour.Red, OutsideColour.Green, OutsideColour.Blue, OutsideColour.Alpha); GL.Vertex3(PosB.X, Altitude, Convert.ToInt32(- PosB.Y)); GL.Vertex3(PosB.X, Altitude, Convert.ToInt32(- PosA.Y)); GL.Color4(InsideColour.Red, InsideColour.Green, InsideColour.Blue, InsideColour.Alpha); GL.Vertex3(PosB.X - BorderInsideThickness, Altitude, - (PosA.Y + BorderInsideThickness)); GL.Vertex3(PosB.X - BorderInsideThickness, Altitude, - (PosB.Y - BorderInsideThickness)); GL.Color4(OutsideColour.Red, OutsideColour.Green, OutsideColour.Blue, OutsideColour.Alpha); GL.Vertex3(PosA.X, Altitude, Convert.ToInt32(- PosB.Y)); GL.Vertex3(PosB.X, Altitude, Convert.ToInt32(- PosB.Y)); GL.Color4(InsideColour.Red, InsideColour.Green, InsideColour.Blue, InsideColour.Alpha); GL.Vertex3(PosB.X - BorderInsideThickness, Altitude, - (PosB.Y - BorderInsideThickness)); GL.Vertex3(PosA.X + BorderInsideThickness, Altitude, Convert.ToInt32(- (PosB.Y - BorderInsideThickness))); }
public List <NameContract> ListUnits() { Event.WriteVerbose("WebService", "ListUnits"); List <NameContract> names = new List <NameContract>(); for (ushort i = 1; i < WebService.HAC.Units.Count; i++) { clsUnit unit = WebService.HAC.Units[i]; if (unit.DefaultProperties == false) { names.Add(new NameContract() { id = i, name = unit.Name }); } } return(names); }
public List <NameContract> ListUnits() { log.Debug("ListUnits"); List <NameContract> names = new List <NameContract>(); for (ushort i = 1; i < WebServiceModule.OmniLink.Controller.Units.Count; i++) { clsUnit unit = WebServiceModule.OmniLink.Controller.Units[i]; if (unit.DefaultProperties == false) { names.Add(new NameContract() { id = i, name = unit.Name }); } } return(names); }
public static UnitContract ConvertUnit(ushort id, clsUnit unit) { UnitContract ret = new UnitContract(); ret.id = id; ret.name = unit.Name; if (unit.Status > 100) { ret.level = (ushort)(unit.Status - 100); } else if (unit.Status == 1) { ret.level = 100; } else { ret.level = 0; } return(ret); }
public static UnitContract ToContract(this clsUnit unit) { UnitContract ret = new UnitContract(); ret.id = (ushort)unit.Number; ret.name = unit.Name; if (unit.Status > 100) { ret.level = (ushort)(unit.Status - 100); } else if (unit.Status == 1) { ret.level = 100; } else { ret.level = 0; } return(ret); }
private void PublishUnits() { log.Debug("Publishing {type}", "units"); for (ushort i = 1; i <= OmniLink.Controller.Units.Count; i++) { clsUnit unit = OmniLink.Controller.Units[i]; if (unit.DefaultProperties == true) { PublishAsync(unit.ToTopic(Topic.name), null); } else { PublishUnitState(unit); PublishAsync(unit.ToTopic(Topic.name), unit.Name); } if (unit.DefaultProperties == true || Global.mqtt_discovery_ignore_units.Contains(unit.Number)) { string type = i < 385 ? "light" : "switch"; PublishAsync($"{Global.mqtt_discovery_prefix}/{type}/{Global.mqtt_prefix}/unit{i}/config", null); continue; } if (i < 385) { PublishAsync($"{Global.mqtt_discovery_prefix}/light/{Global.mqtt_prefix}/unit{i}/config", JsonConvert.SerializeObject(unit.ToConfig())); } else { PublishAsync($"{Global.mqtt_discovery_prefix}/switch/{Global.mqtt_prefix}/unit{i}/config", JsonConvert.SerializeObject(unit.ToConfigSwitch())); } } }
public override clsFactoryBase getCommandFactory(clsUnit objUnit, Field FieldField) { return new facDropResourceFactory(objUnit, FieldField); }
public comMove(clsUnit Unit) : base("Move") { this.m_objUnitToCommand = Unit; }
public facDropResourceFactory(clsUnit objDeliverUnit, Field FieldField) : base(objDeliverUnit, FieldField) { //Init Stuff m_originSektor = FieldField.getSektorForUnit(m_objDeliverUnit); }
private void subSaveECList() { try { if (MessageBox.Show("ECID 리스트를 업데이트 합니다.\n양산중인 장비에서 이 기능을 실행하면\n심각한 문제가 발생 할 수 있습니다.\n진행하겠습니까?", "경고", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No) return; File.Copy(Application.StartupPath + @"\system\System.mdb", Application.StartupPath + @"\system\System.mdb.bak", true); int dintECID = 0; string dstrECName = string.Empty; Single dsngMin = 0; Single dsngECSLL = 0; Single dsngECWLL = 0; Single dsngECDEF = 0; Single dsngECWUL = 0; Single dsngECSUL = 0; Single dsngMax = 0; //string dstrDesc = string.Empty; bool dbolUse = false; string dstrModuleID = string.Empty; #region "유효성검사" for (int dintLoop = 0; dintLoop < dataGridView1.RowCount -1; dintLoop++) { try { dintECID = Convert.ToInt32(dataGridView1.Rows[dintLoop].Cells[0].Value); dstrECName = dataGridView1.Rows[dintLoop].Cells[1].Value.ToString(); dsngMin = Convert.ToInt32(dataGridView1.Rows[dintLoop].Cells[2].Value); dsngECSLL = Convert.ToSingle(dataGridView1.Rows[dintLoop].Cells[3].Value); dsngECWLL = Convert.ToSingle(dataGridView1.Rows[dintLoop].Cells[4].Value); dsngECDEF = Convert.ToSingle(dataGridView1.Rows[dintLoop].Cells[5].Value); dsngECWUL = Convert.ToSingle(dataGridView1.Rows[dintLoop].Cells[6].Value); dsngECSUL = Convert.ToSingle(dataGridView1.Rows[dintLoop].Cells[7].Value); dsngMax = Convert.ToInt32(dataGridView1.Rows[dintLoop].Cells[8].Value); dbolUse = Convert.ToBoolean(dataGridView1.Rows[dintLoop].Cells[10].Value); dstrModuleID = dataGridView1.Rows[dintLoop].Cells[11].Value.ToString().Trim(); if (dsngECSLL > dsngECDEF || dsngECSLL > dsngECSUL || dsngECDEF > dsngECSUL) { MessageBox.Show("ECID: " + dintECID.ToString() + "의 입력값의 범위가 옳지 않습니다.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } bool ModuleIDExist = false; foreach (int dintUnitID in this.pInfo.Unit()) { clsUnit tempUnit = this.pInfo.Unit(dintUnitID); if (tempUnit.SubUnit(0).ModuleID.Equals(dstrModuleID)) { ModuleIDExist = true; break; } } if (!ModuleIDExist) { MessageBox.Show("ECID: " + dintECID.ToString() + "의 ModuleID가 존재하지 않습니다.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } catch { MessageBox.Show("ECID: " + dintECID.ToString() + "의 입력값이 형식이 맞지 않습니다.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } #endregion #region "EC List Update" if (!DBAct.clsDBAct.funBeginTransaction()) { MessageBox.Show("DB Transaction NG!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } //DataAdapter 생성 OleDbDataAdapter dataAdapter = new OleDbDataAdapter("SELECT * FROM tbECID order by ECID", DBAct.clsDBAct.funOleDbConnect()); OleDbCommandBuilder commandBuilder = new OleDbCommandBuilder(dataAdapter); //DataAdapter를 이용하여 DB로 업데이트를 한다. dataAdapter.SelectCommand.Transaction = DBAct.clsDBAct.funOleDbTransaction(); dataAdapter.Update((DataTable)pECIDBindingSource.DataSource); if (!DBAct.clsDBAct.funCommitTransaction()) { MessageBox.Show("DB Commit Transaction NG!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Warning); DBAct.clsDBAct.funRollbackTransaction(); return; } #endregion #region "ECID Reload" string dstrSQL = "SELECT * FROM tbECID order by ECID"; DataTable dDT = DBAct.clsDBAct.funSelectQuery(dstrSQL); int dintIndex = 0; if (dDT != null) { pInfo.Unit(0).SubUnit(0).RemoveECID(); foreach (DataRow dr in dDT.Rows) { dintIndex = Convert.ToInt32(dr["ECID"]); pInfo.Unit(0).SubUnit(0).AddECID(dintIndex); pInfo.Unit(0).SubUnit(0).ECID(dintIndex).Name = dr["ECNAME"].ToString(); //pInfo.Unit(0).SubUnit(0).ECID(dintIndex).Unit = dr["Unit"].ToString(); pInfo.Unit(0).SubUnit(0).ECID(dintIndex).Min = dr["Min"].ToString(); pInfo.Unit(0).SubUnit(0).ECID(dintIndex).ECDEF = dr["ECDEF"].ToString(); pInfo.Unit(0).SubUnit(0).ECID(dintIndex).Max = dr["Max"].ToString(); //pInfo.Unit(0).SubUnit(0).ECID(dintIndex).Use = Convert.ToBoolean(dr["Use"]); pInfo.Unit(0).SubUnit(0).ECID(dintIndex).Format = dr["Format"].ToString(); pInfo.Unit(0).SubUnit(0).ECID(dintIndex).DESC = dr["Description"].ToString(); pInfo.Unit(0).SubUnit(0).ECID(dintIndex).UnitID = 0; pInfo.Unit(0).SubUnit(0).ECID(dintIndex).ModuleID = dr["ModuleID"].ToString(); } this.pInfo.All.HOSTReportECIDCount = dDT.Rows.Count; pInfo.DeleteTable("ECID"); pInfo.AddDataTable("ECID", dDT); tabfrmSetupECID_Load(this, null); } subSaveLastModified(); MessageBox.Show("Data Save Success!", "Jobs Complete", MessageBoxButtons.OK, MessageBoxIcon.Information); #endregion } catch (Exception ex) { pInfo.subLog_Set(InfoAct.clsInfo.LogType.CIM, ex.ToString()); MessageBox.Show("EC List Update Fail!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
public clsUnit PlaceUnit(UnitTypeBase TypeBase, WorldPos Pos, clsUnitGroup UnitGroup, int Rotation) { var TilePosA = new XYInt(); var TilePosB = new XYInt(); var X2 = 0; var Y2 = 0; var FinalTilePos = new XYInt(); var Footprint = new XYInt(); var NewUnitAdd = new clsUnitAdd(); NewUnitAdd.Map = Map; NewUnitAdd.StoreChange = true; var NewUnit = new clsUnit(); NewUnitAdd.NewUnit = NewUnit; NewUnit.TypeBase = TypeBase; NewUnit.UnitGroup = UnitGroup; FinalTilePos.X = Pos.Horizontal.X / Constants.TerrainGridSpacing; FinalTilePos.Y = Pos.Horizontal.Y / Constants.TerrainGridSpacing; Footprint = TypeBase.get_GetFootprintSelected(Rotation); NewUnit.Pos = Pos; TilePosA.X = (int)(((double)NewUnit.Pos.Horizontal.X / Constants.TerrainGridSpacing - Footprint.X / 2.0D + 0.5D)); TilePosA.Y = (int)(((double)NewUnit.Pos.Horizontal.Y / Constants.TerrainGridSpacing - Footprint.Y / 2.0D + 0.5D)); TilePosB.X = (int)((double)NewUnit.Pos.Horizontal.X / Constants.TerrainGridSpacing + Footprint.X / 2.0D - 0.5D); TilePosB.Y = (int)((double)NewUnit.Pos.Horizontal.Y / Constants.TerrainGridSpacing + Footprint.Y / 2.0D - 0.5D); NewUnit.Rotation = Rotation; NewUnitAdd.Perform(); for ( Y2 = Math.Max(TilePosA.Y, 0); Y2 <= Math.Min(TilePosB.Y, Map.Terrain.TileSize.Y - 1); Y2++ ) { for ( X2 = Math.Max(TilePosA.X, 0); X2 <= Math.Min(TilePosB.X, Map.Terrain.TileSize.X - 1); X2++ ) { TileNodeBlock(X2, Y2); } } TilePathMap.FindCalc(); return NewUnit; }
public override clsFactoryBase getCommandFactory(clsUnit objUnit, Field FieldField) { return new facPlaceUnitFactory(objUnit, FieldField); }
public static string ToState(this clsUnit unit) { return(unit.Status == 0 || unit.Status == 100 ? "OFF" : "ON"); }
private clsResult Read_FMap_Objects(StreamReader File) { clsResult ReturnResult = new clsResult("Reading objects"); int A = 0; IniReader ObjectsINI = new IniReader(); ReturnResult.Take(ObjectsINI.ReadFile(File)); FMapIniObjects INIObjects = new FMapIniObjects(ObjectsINI.Sections.Count); ReturnResult.Take(ObjectsINI.Translate(INIObjects)); int DroidComponentUnknownCount = 0; int ObjectTypeMissingCount = 0; int ObjectPlayerNumInvalidCount = 0; int ObjectPosInvalidCount = 0; int DesignTypeUnspecifiedCount = 0; int UnknownUnitTypeCount = 0; int MaxUnknownUnitTypeWarningCount = 16; clsDroidDesign DroidDesign = default(clsDroidDesign); clsUnit NewObject = default(clsUnit); clsUnitAdd UnitAdd = new clsUnitAdd(); clsUnitType UnitType = default(clsUnitType); bool IsDesign = default(bool); clsUnitGroup UnitGroup = default(clsUnitGroup); sXY_int ZeroPos = new sXY_int(0, 0); UInt32 AvailableID = 0; UnitAdd.Map = this; AvailableID = 1U; for ( A = 0; A <= INIObjects.ObjectCount - 1; A++ ) { if ( INIObjects.Objects[A].ID >= AvailableID ) { AvailableID = INIObjects.Objects[A].ID + 1U; } } for ( A = 0; A <= INIObjects.ObjectCount - 1; A++ ) { if ( INIObjects.Objects[A].Pos == null ) { ObjectPosInvalidCount++; } else if ( !App.PosIsWithinTileArea(INIObjects.Objects[A].Pos.XY, ZeroPos, Terrain.TileSize) ) { ObjectPosInvalidCount++; } else { UnitType = null; if ( INIObjects.Objects[A].Type != clsUnitType.enumType.Unspecified ) { IsDesign = false; if ( INIObjects.Objects[A].Type == clsUnitType.enumType.PlayerDroid ) { if ( !INIObjects.Objects[A].IsTemplate ) { IsDesign = true; } } if ( IsDesign ) { DroidDesign = new clsDroidDesign(); DroidDesign.TemplateDroidType = INIObjects.Objects[A].TemplateDroidType; if ( DroidDesign.TemplateDroidType == null ) { DroidDesign.TemplateDroidType = App.TemplateDroidType_Droid; DesignTypeUnspecifiedCount++; } if ( INIObjects.Objects[A].BodyCode != "" ) { DroidDesign.Body = App.ObjectData.FindOrCreateBody(Convert.ToString(INIObjects.Objects[A].BodyCode)); if ( DroidDesign.Body.IsUnknown ) { DroidComponentUnknownCount++; } } if ( INIObjects.Objects[A].PropulsionCode != "" ) { DroidDesign.Propulsion = App.ObjectData.FindOrCreatePropulsion(INIObjects.Objects[A].PropulsionCode); if ( DroidDesign.Propulsion.IsUnknown ) { DroidComponentUnknownCount++; } } DroidDesign.TurretCount = (byte)(INIObjects.Objects[A].TurretCount); if ( INIObjects.Objects[A].TurretCodes[0] != "" ) { DroidDesign.Turret1 = App.ObjectData.FindOrCreateTurret(INIObjects.Objects[A].TurretTypes[0], Convert.ToString(INIObjects.Objects[A].TurretCodes[0])); if ( DroidDesign.Turret1.IsUnknown ) { DroidComponentUnknownCount++; } } if ( INIObjects.Objects[A].TurretCodes[1] != "" ) { DroidDesign.Turret2 = App.ObjectData.FindOrCreateTurret(INIObjects.Objects[A].TurretTypes[1], Convert.ToString(INIObjects.Objects[A].TurretCodes[1])); if ( DroidDesign.Turret2.IsUnknown ) { DroidComponentUnknownCount++; } } if ( INIObjects.Objects[A].TurretCodes[2] != "" ) { DroidDesign.Turret3 = App.ObjectData.FindOrCreateTurret(INIObjects.Objects[A].TurretTypes[2], Convert.ToString(INIObjects.Objects[A].TurretCodes[2])); if ( DroidDesign.Turret3.IsUnknown ) { DroidComponentUnknownCount++; } } DroidDesign.UpdateAttachments(); UnitType = DroidDesign; } else { UnitType = App.ObjectData.FindOrCreateUnitType(INIObjects.Objects[A].Code, INIObjects.Objects[A].Type, INIObjects.Objects[A].WallType); if ( UnitType.IsUnknown ) { if ( UnknownUnitTypeCount < MaxUnknownUnitTypeWarningCount ) { ReturnResult.WarningAdd(ControlChars.Quote + INIObjects.Objects[A].Code + Convert.ToString(ControlChars.Quote) + " is not a loaded object."); } UnknownUnitTypeCount++; } } } if ( UnitType == null ) { ObjectTypeMissingCount++; } else { NewObject = new clsUnit(); NewObject.Type = UnitType; NewObject.Pos.Horizontal.X = INIObjects.Objects[A].Pos.X; NewObject.Pos.Horizontal.Y = INIObjects.Objects[A].Pos.Y; NewObject.Health = INIObjects.Objects[A].Health; NewObject.SavePriority = INIObjects.Objects[A].Priority; NewObject.Rotation = (int)(INIObjects.Objects[A].Heading); if ( NewObject.Rotation >= 360 ) { NewObject.Rotation -= 360; } if ( INIObjects.Objects[A].UnitGroup == null || INIObjects.Objects[A].UnitGroup == "" ) { if ( INIObjects.Objects[A].Type != clsUnitType.enumType.Feature ) { ObjectPlayerNumInvalidCount++; } NewObject.UnitGroup = ScavengerUnitGroup; } else { if ( INIObjects.Objects[A].UnitGroup.ToLower() == "scavenger" ) { NewObject.UnitGroup = ScavengerUnitGroup; } else { UInt32 PlayerNum = 0; try { if ( !IOUtil.InvariantParse(INIObjects.Objects[A].UnitGroup, PlayerNum) ) { throw (new Exception()); } if ( PlayerNum < Constants.PlayerCountMax ) { UnitGroup = UnitGroups[Convert.ToInt32(PlayerNum)]; } else { UnitGroup = ScavengerUnitGroup; ObjectPlayerNumInvalidCount++; } } catch ( Exception ) { ObjectPlayerNumInvalidCount++; UnitGroup = ScavengerUnitGroup; } NewObject.UnitGroup = UnitGroup; } } if ( INIObjects.Objects[A].ID == 0U ) { INIObjects.Objects[A].ID = AvailableID; App.ZeroIDWarning(NewObject, INIObjects.Objects[A].ID, ReturnResult); } UnitAdd.NewUnit = NewObject; UnitAdd.ID = INIObjects.Objects[A].ID; UnitAdd.Label = INIObjects.Objects[A].Label; UnitAdd.Perform(); App.ErrorIDChange(INIObjects.Objects[A].ID, NewObject, "Read_FMap_Objects"); if ( AvailableID == INIObjects.Objects[A].ID ) { AvailableID = NewObject.ID + 1U; } } } } if ( UnknownUnitTypeCount > MaxUnknownUnitTypeWarningCount ) { ReturnResult.WarningAdd(UnknownUnitTypeCount + " objects were not in the loaded object data."); } if ( ObjectTypeMissingCount > 0 ) { ReturnResult.WarningAdd(ObjectTypeMissingCount + " objects did not specify a type and were ignored."); } if ( DroidComponentUnknownCount > 0 ) { ReturnResult.WarningAdd(DroidComponentUnknownCount + " components used by droids were loaded as unknowns."); } if ( ObjectPlayerNumInvalidCount > 0 ) { ReturnResult.WarningAdd(ObjectPlayerNumInvalidCount + " objects had an invalid player number and were set to player 0."); } if ( ObjectPosInvalidCount > 0 ) { ReturnResult.WarningAdd(ObjectPosInvalidCount + " objects had a position that was off-map and were ignored."); } if ( DesignTypeUnspecifiedCount > 0 ) { ReturnResult.WarningAdd(DesignTypeUnspecifiedCount + " designed droids did not specify a template droid type and were set to droid."); } return ReturnResult; }
public override clsFactoryBase getCommandFactory(clsUnit objUnit, Field FieldField) { return new facSolveKollision(objUnit, FieldField); }
public static string ToTopic(this clsUnit unit, Topic topic) { return($"{Global.mqtt_prefix}/unit{unit.Number.ToString()}/{topic.ToString()}"); }
private void btnAdd_Click(object sender, EventArgs e) { decimal outResult = 0; bool bResult = false; bResult = decimal.TryParse(txtWidth.Text, out outResult); if (bResult == false) { MessageBox.Show("Please specify a valid width."); return; } bResult = decimal.TryParse(txtArea.Text, out outResult); if (bResult == false) { MessageBox.Show("Please specify a valid area."); return; } bResult = decimal.TryParse(txtLength.Text, out outResult); if (bResult == false) { MessageBox.Show("Please specify a valid length."); return; } bResult = decimal.TryParse(txtPrice.Text, out outResult); if (bResult == false) { MessageBox.Show("Please specify a valid price."); return; } if (cmbProjectID.Text == "") { MessageBox.Show("Please select a project."); return; } if (cmbBlockID.Text == "") { MessageBox.Show("Please select a block."); return; } if (cmbUnitType.Text == "") { MessageBox.Show("Please select a valid category."); return; } if (cmbUnitCategory.Text == "") { MessageBox.Show("Please select a valid nature."); return; } if (txtUnitID.Text == "") { MessageBox.Show("Please enter a valid unit id."); return; } if (id == 0) { txtStatus.Text = "Available"; } bool b = da.GetUnitIDAvailability(txtUnitID.Text); if (b == false) { MessageBox.Show("The unit id has already been used. Please enter a new unit id"); return; } clsUnit unit = new clsUnit() { strUnitTypeID = cmbUnitType.Text, strNumber = strNumber, strPrefix = strPrefix, strRegistrationNo = txtRegistrationNo.Text, strBlockNo = cmbBlockID.Text, strProjectID = cmbProjectID.Text, strSizeCode = cmbSizeCode.Text, strStatus = txtStatus.Text, strStreetNo = txtStreetNo.Text, strPlotNo = txtPlotNo.Text, strUnitID = txtUnitID.Text.ToUpper(), strUnitCategoryID = cmbUnitCategory.Text, decWidth = Convert.ToDecimal(txtWidth.Text), decLength = Convert.ToDecimal(txtLength.Text), strUOMID = txtUom.Text.ToUpper(), decPrice = Convert.ToDecimal(txtPrice.Text), decArea = Convert.ToDecimal(txtArea.Text), decSquareFeet = Convert.ToDecimal(txtSquareFeets.Text), ID = this.id }; if (this.id == 0) { unit.statuscode = (int)unitLookupCodes.Available; } bool result = da.AddUnit(unit); LoadGrid(); }
public clsMap(clsMap MapToCopy, sXY_int Offset, sXY_int Area) { frmMainLink = new ConnectedListLink<clsMap, frmMain>(this); Gateways = new ConnectedList<clsGateway, clsMap>(this); int EndX = 0; int EndY = 0; int X = 0; int Y = 0; Initialize(); //make some map data for selection EndX = Math.Min(MapToCopy.Terrain.TileSize.X - Offset.X, Area.X); EndY = Math.Min(MapToCopy.Terrain.TileSize.Y - Offset.Y, Area.Y); Terrain = new clsTerrain(Area); for ( Y = 0; Y <= Terrain.TileSize.Y - 1; Y++ ) { for ( X = 0; X <= Terrain.TileSize.X - 1; X++ ) { Terrain.Tiles[X, Y].Texture.TextureNum = -1; } } for ( Y = 0; Y <= EndY; Y++ ) { for ( X = 0; X <= EndX; X++ ) { Terrain.Vertices[X, Y].Height = MapToCopy.Terrain.Vertices[Offset.X + X, Offset.Y + Y].Height; Terrain.Vertices[X, Y].Terrain = MapToCopy.Terrain.Vertices[Offset.X + X, Offset.Y + Y].Terrain; } } for ( Y = 0; Y <= EndY - 1; Y++ ) { for ( X = 0; X <= EndX - 1; X++ ) { Terrain.Tiles[X, Y].Copy(MapToCopy.Terrain.Tiles[Offset.X + X, Offset.Y + Y]); } } for ( Y = 0; Y <= EndY; Y++ ) { for ( X = 0; X <= EndX - 1; X++ ) { Terrain.SideH[X, Y].Road = MapToCopy.Terrain.SideH[Offset.X + X, Offset.Y + Y].Road; } } for ( Y = 0; Y <= EndY - 1; Y++ ) { for ( X = 0; X <= EndX; X++ ) { Terrain.SideV[X, Y].Road = MapToCopy.Terrain.SideV[Offset.X + X, Offset.Y + Y].Road; } } SectorCount.X = (int)(Math.Ceiling((double)(Area.X / Constants.SectorTileSize))); SectorCount.Y = (int)(Math.Ceiling((double)(Area.Y / Constants.SectorTileSize))); Sectors = new clsSector[SectorCount.X, SectorCount.Y]; for ( Y = 0; Y <= SectorCount.Y - 1; Y++ ) { for ( X = 0; X <= SectorCount.X - 1; X++ ) { Sectors[X, Y] = new clsSector(new sXY_int(X, Y)); } } sXY_int PosDif = new sXY_int(); clsUnitAdd NewUnitAdd = new clsUnitAdd(); NewUnitAdd.Map = this; clsUnit NewUnit = default(clsUnit); clsGateway Gateway = default(clsGateway); foreach ( clsGateway tempLoopVar_Gateway in MapToCopy.Gateways ) { Gateway = tempLoopVar_Gateway; GatewayCreate(new sXY_int(Gateway.PosA.X - Offset.X, Gateway.PosA.Y - Offset.Y), new sXY_int(Gateway.PosB.X - Offset.X, Gateway.PosB.Y - Offset.Y)); } PosDif.X = - Offset.X * App.TerrainGridSpacing; PosDif.Y = - Offset.Y * App.TerrainGridSpacing; clsUnit Unit = default(clsUnit); sXY_int NewPos = new sXY_int(); foreach ( clsUnit tempLoopVar_Unit in MapToCopy.Units ) { Unit = tempLoopVar_Unit; NewPos = Unit.Pos.Horizontal + PosDif; if ( PosIsOnMap(NewPos) ) { NewUnit = new clsUnit(Unit, this); NewUnit.Pos.Horizontal = NewPos; NewUnitAdd.NewUnit = NewUnit; NewUnitAdd.Label = Unit.Label; NewUnitAdd.Perform(); } } }
public comPlaceUnit(clsUnit Unit) : base("PlaceUnit") { this.m_objUnitToCommand = Unit; }
public comCreateResource(clsUnit objRecieveUnit) : base("CreateResource") { this.m_objRecieveUnit = objRecieveUnit; }
public comDropResource(clsUnit objDeliverUnit, clsUnit objRecieveUnit) : base("DropResource") { this.m_objDeliverUnit = objDeliverUnit; this.m_objRecieveUnit = objRecieveUnit; }
public clsUnit PlaceUnitNear(UnitTypeBase TypeBase, XYInt Pos, clsUnitGroup UnitGroup, int Clearance, int Rotation, int MaxDistFromPos) { var PosNode = default(PathfinderNode); var NodeTag = default(clsNodeTag); var FinalTilePos = new XYInt(); var TilePosA = new XYInt(); var TilePosB = new XYInt(); var X2 = 0; var Y2 = 0; var Remainder = 0; var Footprint = new XYInt(); PosNode = GetNearestNodeConnection(TilePathMap, Pos, Clearance, MaxDistFromPos); if ( PosNode != null ) { NodeTag = (clsNodeTag)PosNode.Tag; if ( (Pos - NodeTag.Pos).ToDoubles().GetMagnitude() <= MaxDistFromPos ) { var NewUnitAdd = new clsUnitAdd(); NewUnitAdd.Map = Map; NewUnitAdd.StoreChange = true; var NewUnit = new clsUnit(); NewUnitAdd.NewUnit = NewUnit; NewUnit.TypeBase = TypeBase; NewUnit.UnitGroup = UnitGroup; FinalTilePos.X = NodeTag.Pos.X / Constants.TerrainGridSpacing; FinalTilePos.Y = (NodeTag.Pos.Y / Constants.TerrainGridSpacing); Footprint = TypeBase.get_GetFootprintSelected(Rotation); Remainder = Footprint.X % 2; if ( Remainder > 0 ) { NewUnit.Pos.Horizontal.X = NodeTag.Pos.X; } else { if ( App.Random.Next() >= 0.5F ) { NewUnit.Pos.Horizontal.X = (int)(NodeTag.Pos.X - Constants.TerrainGridSpacing / 2.0D); } else { NewUnit.Pos.Horizontal.X = (int)(NodeTag.Pos.X + Constants.TerrainGridSpacing / 2.0D); } } Remainder = Footprint.Y % 2; if ( Remainder > 0 ) { NewUnit.Pos.Horizontal.Y = NodeTag.Pos.Y; } else { if ( App.Random.Next() >= 0.5F ) { NewUnit.Pos.Horizontal.Y = (int)(NodeTag.Pos.Y - Constants.TerrainGridSpacing / 2.0D); } else { NewUnit.Pos.Horizontal.Y = (int)(NodeTag.Pos.Y + Constants.TerrainGridSpacing / 2.0D); } } TilePosA.X = (int)((double)NewUnit.Pos.Horizontal.X / Constants.TerrainGridSpacing - Footprint.X / 2.0D + 0.5D); TilePosA.Y = (int)((double)NewUnit.Pos.Horizontal.Y / Constants.TerrainGridSpacing - Footprint.Y / 2.0D + 0.5D); TilePosB.X = (int)(((double)NewUnit.Pos.Horizontal.X / Constants.TerrainGridSpacing + Footprint.X / 2.0D - 0.5D)); TilePosB.Y = (int)(((double)NewUnit.Pos.Horizontal.Y / Constants.TerrainGridSpacing + Footprint.Y / 2.0D - 0.5D)); NewUnit.Rotation = Rotation; NewUnitAdd.Perform(); for ( Y2 = Math.Max(TilePosA.Y, 0); Y2 <= Math.Min(TilePosB.Y, Map.Terrain.TileSize.Y - 1); Y2++ ) { for ( X2 = Math.Max(TilePosA.X, 0); X2 <= Math.Min(TilePosB.X, Map.Terrain.TileSize.X - 1); X2++ ) { TileNodeBlock(X2, Y2); } } TilePathMap.FindCalc(); return NewUnit; } return null; } return null; }
public void UnitSectorsCalc(clsUnit Unit) { sXY_int Start = new sXY_int(); sXY_int Finish = new sXY_int(); sXY_int TileStart = new sXY_int(); sXY_int TileFinish = new sXY_int(); clsUnitSectorConnection Connection; int X = 0; int Y = 0; GetFootprintTileRangeClamped(Unit.Pos.Horizontal, Unit.Type.get_GetFootprintSelected(Unit.Rotation), TileStart, TileFinish); Start = GetTileSectorNum(TileStart); Finish = GetTileSectorNum(TileFinish); Start.X = MathUtil.Clamp_int(Start.X, 0, SectorCount.X - 1); Start.Y = MathUtil.Clamp_int(Start.Y, 0, SectorCount.Y - 1); Finish.X = MathUtil.Clamp_int(Finish.X, 0, SectorCount.X - 1); Finish.Y = MathUtil.Clamp_int(Finish.Y, 0, SectorCount.Y - 1); Unit.Sectors.Clear(); for ( Y = Start.Y; Y <= Finish.Y; Y++ ) { for ( X = Start.X; X <= Finish.X; X++ ) { Connection = clsUnitSectorConnection.Create(Unit, Sectors[X, Y]); } } }
public clsResult CreateWZObjects(sCreateWZObjectsArgs Args) { clsResult ReturnResult = new clsResult("Creating objects"); clsUnit NewUnit = default(clsUnit); UInt32 AvailableID = 0; SimpleClassList<clsWZBJOUnit> BJOUnits = Args.BJOUnits; IniStructures INIStructures = Args.INIStructures; IniDroids INIDroids = Args.INIDroids; IniFeatures INIFeatures = Args.INIFeatures; clsUnitAdd UnitAdd = new clsUnitAdd(); int A = 0; int B = 0; clsWZBJOUnit BJOUnit = default(clsWZBJOUnit); UnitAdd.Map = this; AvailableID = 1U; foreach ( clsWZBJOUnit tempLoopVar_BJOUnit in BJOUnits ) { BJOUnit = tempLoopVar_BJOUnit; if ( BJOUnit.ID >= AvailableID ) { AvailableID = BJOUnit.ID + 1U; } } if ( INIStructures != null ) { for ( A = 0; A <= INIStructures.StructureCount - 1; A++ ) { if ( INIStructures.Structures[A].ID >= AvailableID ) { AvailableID = INIStructures.Structures[A].ID + 1U; } } } if ( INIFeatures != null ) { for ( A = 0; A <= INIFeatures.FeatureCount - 1; A++ ) { if ( INIFeatures.Features[A].ID >= AvailableID ) { AvailableID = INIFeatures.Features[A].ID + 1U; } } } if ( INIDroids != null ) { for ( A = 0; A <= INIDroids.DroidCount - 1; A++ ) { if ( INIDroids.Droids[A].ID >= AvailableID ) { AvailableID = INIDroids.Droids[A].ID + 1U; } } } foreach ( clsWZBJOUnit tempLoopVar_BJOUnit in BJOUnits ) { BJOUnit = tempLoopVar_BJOUnit; NewUnit = new clsUnit(); NewUnit.ID = BJOUnit.ID; NewUnit.Type = App.ObjectData.FindOrCreateUnitType(BJOUnit.Code, BJOUnit.ObjectType, -1); if ( NewUnit.Type == null ) { ReturnResult.ProblemAdd("Unable to create object type."); return ReturnResult; } if ( BJOUnit.Player >= Constants.PlayerCountMax ) { NewUnit.UnitGroup = ScavengerUnitGroup; } else { NewUnit.UnitGroup = UnitGroups[Convert.ToInt32(BJOUnit.Player)]; } NewUnit.Pos = BJOUnit.Pos; NewUnit.Rotation = (int)(Math.Min(BJOUnit.Rotation, 359U)); if ( BJOUnit.ID == 0U ) { BJOUnit.ID = AvailableID; App.ZeroIDWarning(NewUnit, BJOUnit.ID, ReturnResult); } UnitAdd.NewUnit = NewUnit; UnitAdd.ID = BJOUnit.ID; UnitAdd.Perform(); App.ErrorIDChange(BJOUnit.ID, NewUnit, "CreateWZObjects"); if ( AvailableID == BJOUnit.ID ) { AvailableID = NewUnit.ID + 1U; } } clsStructureType StructureType = default(clsStructureType); clsDroidDesign DroidType = default(clsDroidDesign); clsFeatureType FeatureType = default(clsFeatureType); clsDroidDesign.sLoadPartsArgs LoadPartsArgs = new clsDroidDesign.sLoadPartsArgs(); clsUnitType UnitType = null; int ErrorCount = 0; int UnknownDroidComponentCount = 0; int UnknownDroidTypeCount = 0; int DroidBadPositionCount = 0; int StructureBadPositionCount = 0; int StructureBadModulesCount = 0; int FeatureBadPositionCount = 0; int ModuleLimit = 0; sXY_int ZeroPos = new sXY_int(0, 0); clsStructureType ModuleType = default(clsStructureType); clsUnit NewModule = default(clsUnit); clsStructureType FactoryModule = App.ObjectData.FindFirstStructureType(clsStructureType.enumStructureType.FactoryModule); clsStructureType ResearchModule = App.ObjectData.FindFirstStructureType(clsStructureType.enumStructureType.ResearchModule); clsStructureType PowerModule = App.ObjectData.FindFirstStructureType(clsStructureType.enumStructureType.PowerModule); if ( FactoryModule == null ) { ReturnResult.WarningAdd("No factory module loaded."); } if ( ResearchModule == null ) { ReturnResult.WarningAdd("No research module loaded."); } if ( PowerModule == null ) { ReturnResult.WarningAdd("No power module loaded."); } if ( INIStructures != null ) { for ( A = 0; A <= INIStructures.StructureCount - 1; A++ ) { if ( INIStructures.Structures[A].Pos == null ) { StructureBadPositionCount++; } else if ( !App.PosIsWithinTileArea(INIStructures.Structures[A].Pos.WorldPos.Horizontal, ZeroPos, Terrain.TileSize) ) { StructureBadPositionCount++; } else { UnitType = App.ObjectData.FindOrCreateUnitType(Convert.ToString(INIStructures.Structures[A].Code), clsUnitType.enumType.PlayerStructure, INIStructures.Structures[A].WallType); if ( UnitType.Type == clsUnitType.enumType.PlayerStructure ) { StructureType = (clsStructureType)UnitType; } else { StructureType = null; } if ( StructureType == null ) { ErrorCount++; } else { NewUnit = new clsUnit(); NewUnit.Type = StructureType; if ( INIStructures.Structures[A].UnitGroup == null ) { NewUnit.UnitGroup = ScavengerUnitGroup; } else { NewUnit.UnitGroup = INIStructures.Structures[A].UnitGroup; } NewUnit.Pos = INIStructures.Structures[A].Pos.WorldPos; NewUnit.Rotation = Convert.ToInt32(INIStructures.Structures[A].Rotation.Direction * 360.0D / App.INIRotationMax); if ( NewUnit.Rotation == 360 ) { NewUnit.Rotation = 0; } if ( INIStructures.Structures[A].HealthPercent >= 0 ) { NewUnit.Health = MathUtil.Clamp_dbl(INIStructures.Structures[A].HealthPercent / 100.0D, 0.01D, 1.0D); } if ( INIStructures.Structures[A].ID == 0U ) { INIStructures.Structures[A].ID = AvailableID; App.ZeroIDWarning(NewUnit, INIStructures.Structures[A].ID, ReturnResult); } UnitAdd.NewUnit = NewUnit; UnitAdd.ID = INIStructures.Structures[A].ID; UnitAdd.Perform(); App.ErrorIDChange(INIStructures.Structures[A].ID, NewUnit, "Load_WZ->INIStructures"); if ( AvailableID == INIStructures.Structures[A].ID ) { AvailableID = NewUnit.ID + 1U; } //create modules switch ( StructureType.StructureType ) { case clsStructureType.enumStructureType.Factory: ModuleLimit = 2; ModuleType = FactoryModule; break; case clsStructureType.enumStructureType.VTOLFactory: ModuleLimit = 2; ModuleType = FactoryModule; break; case clsStructureType.enumStructureType.PowerGenerator: ModuleLimit = 1; ModuleType = PowerModule; break; case clsStructureType.enumStructureType.Research: ModuleLimit = 1; ModuleType = ResearchModule; break; default: ModuleLimit = 0; ModuleType = null; break; } if ( INIStructures.Structures[A].ModuleCount > ModuleLimit ) { INIStructures.Structures[A].ModuleCount = ModuleLimit; StructureBadModulesCount++; } else if ( INIStructures.Structures[A].ModuleCount < 0 ) { INIStructures.Structures[A].ModuleCount = 0; StructureBadModulesCount++; } if ( ModuleType != null ) { for ( B = 0; B <= INIStructures.Structures[A].ModuleCount - 1; B++ ) { NewModule = new clsUnit(); NewModule.Type = ModuleType; NewModule.UnitGroup = NewUnit.UnitGroup; NewModule.Pos = NewUnit.Pos; NewModule.Rotation = NewUnit.Rotation; UnitAdd.NewUnit = NewModule; UnitAdd.ID = AvailableID; UnitAdd.Perform(); AvailableID = NewModule.ID + 1U; } } } } } if ( StructureBadPositionCount > 0 ) { ReturnResult.WarningAdd(StructureBadPositionCount + " structures had an invalid position and were removed."); } if ( StructureBadModulesCount > 0 ) { ReturnResult.WarningAdd(StructureBadModulesCount + " structures had an invalid number of modules."); } } if ( INIFeatures != null ) { for ( A = 0; A <= INIFeatures.FeatureCount - 1; A++ ) { if ( INIFeatures.Features[A].Pos == null ) { FeatureBadPositionCount++; } else if ( !App.PosIsWithinTileArea(INIFeatures.Features[A].Pos.WorldPos.Horizontal, ZeroPos, Terrain.TileSize) ) { FeatureBadPositionCount++; } else { UnitType = App.ObjectData.FindOrCreateUnitType(Convert.ToString(INIFeatures.Features[A].Code), clsUnitType.enumType.Feature, -1); if ( UnitType.Type == clsUnitType.enumType.Feature ) { FeatureType = (clsFeatureType)UnitType; } else { FeatureType = null; } if ( FeatureType == null ) { ErrorCount++; } else { NewUnit = new clsUnit(); NewUnit.Type = FeatureType; NewUnit.UnitGroup = ScavengerUnitGroup; NewUnit.Pos = INIFeatures.Features[A].Pos.WorldPos; NewUnit.Rotation = Convert.ToInt32(INIFeatures.Features[A].Rotation.Direction * 360.0D / App.INIRotationMax); if ( NewUnit.Rotation == 360 ) { NewUnit.Rotation = 0; } if ( INIFeatures.Features[A].HealthPercent >= 0 ) { NewUnit.Health = MathUtil.Clamp_dbl(INIFeatures.Features[A].HealthPercent / 100.0D, 0.01D, 1.0D); } if ( INIFeatures.Features[A].ID == 0U ) { INIFeatures.Features[A].ID = AvailableID; App.ZeroIDWarning(NewUnit, INIFeatures.Features[A].ID, ReturnResult); } UnitAdd.NewUnit = NewUnit; UnitAdd.ID = INIFeatures.Features[A].ID; UnitAdd.Perform(); App.ErrorIDChange(INIFeatures.Features[A].ID, NewUnit, "Load_WZ->INIFeatures"); if ( AvailableID == INIFeatures.Features[A].ID ) { AvailableID = NewUnit.ID + 1U; } } } } if ( FeatureBadPositionCount > 0 ) { ReturnResult.WarningAdd(FeatureBadPositionCount + " features had an invalid position and were removed."); } } if ( INIDroids != null ) { for ( A = 0; A <= INIDroids.DroidCount - 1; A++ ) { if ( INIDroids.Droids[A].Pos == null ) { DroidBadPositionCount++; } else if ( !App.PosIsWithinTileArea(INIDroids.Droids[A].Pos.WorldPos.Horizontal, ZeroPos, Terrain.TileSize) ) { DroidBadPositionCount++; } else { if ( INIDroids.Droids[A].Template == null || INIDroids.Droids[A].Template == "" ) { DroidType = new clsDroidDesign(); if ( !DroidType.SetDroidType((App.enumDroidType)(INIDroids.Droids[A].DroidType)) ) { UnknownDroidTypeCount++; } LoadPartsArgs.Body = App.ObjectData.FindOrCreateBody(INIDroids.Droids[A].Body); if ( LoadPartsArgs.Body == null ) { UnknownDroidComponentCount++; } else { if ( LoadPartsArgs.Body.IsUnknown ) { UnknownDroidComponentCount++; } } LoadPartsArgs.Propulsion = App.ObjectData.FindOrCreatePropulsion(Convert.ToString(INIDroids.Droids[A].Propulsion)); if ( LoadPartsArgs.Propulsion == null ) { UnknownDroidComponentCount++; } else { if ( LoadPartsArgs.Propulsion.IsUnknown ) { UnknownDroidComponentCount++; } } LoadPartsArgs.Construct = App.ObjectData.FindOrCreateConstruct(Convert.ToString(INIDroids.Droids[A].Construct)); if ( LoadPartsArgs.Construct == null ) { UnknownDroidComponentCount++; } else { if ( LoadPartsArgs.Construct.IsUnknown ) { UnknownDroidComponentCount++; } } LoadPartsArgs.Repair = App.ObjectData.FindOrCreateRepair(INIDroids.Droids[A].Repair); if ( LoadPartsArgs.Repair == null ) { UnknownDroidComponentCount++; } else { if ( LoadPartsArgs.Repair.IsUnknown ) { UnknownDroidComponentCount++; } } LoadPartsArgs.Sensor = App.ObjectData.FindOrCreateSensor(INIDroids.Droids[A].Sensor); if ( LoadPartsArgs.Sensor == null ) { UnknownDroidComponentCount++; } else { if ( LoadPartsArgs.Sensor.IsUnknown ) { UnknownDroidComponentCount++; } } LoadPartsArgs.Brain = App.ObjectData.FindOrCreateBrain(INIDroids.Droids[A].Brain); if ( LoadPartsArgs.Brain == null ) { UnknownDroidComponentCount++; } else { if ( LoadPartsArgs.Brain.IsUnknown ) { UnknownDroidComponentCount++; } } LoadPartsArgs.ECM = App.ObjectData.FindOrCreateECM(Convert.ToString(INIDroids.Droids[A].ECM)); if ( LoadPartsArgs.ECM == null ) { UnknownDroidComponentCount++; } else { if ( LoadPartsArgs.ECM.IsUnknown ) { UnknownDroidComponentCount++; } } LoadPartsArgs.Weapon1 = App.ObjectData.FindOrCreateWeapon(Convert.ToString(INIDroids.Droids[A].Weapons[0])); if ( LoadPartsArgs.Weapon1 == null ) { UnknownDroidComponentCount++; } else { if ( LoadPartsArgs.Weapon1.IsUnknown ) { UnknownDroidComponentCount++; } } LoadPartsArgs.Weapon2 = App.ObjectData.FindOrCreateWeapon(Convert.ToString(INIDroids.Droids[A].Weapons[1])); if ( LoadPartsArgs.Weapon2 == null ) { UnknownDroidComponentCount++; } else { if ( LoadPartsArgs.Weapon2.IsUnknown ) { UnknownDroidComponentCount++; } } LoadPartsArgs.Weapon3 = App.ObjectData.FindOrCreateWeapon(Convert.ToString(INIDroids.Droids[A].Weapons[2])); if ( LoadPartsArgs.Weapon3 == null ) { UnknownDroidComponentCount++; } else { if ( LoadPartsArgs.Weapon3.IsUnknown ) { UnknownDroidComponentCount++; } } DroidType.LoadParts(LoadPartsArgs); } else { UnitType = App.ObjectData.FindOrCreateUnitType(INIDroids.Droids[A].Template, clsUnitType.enumType.PlayerDroid, -1); if ( UnitType == null ) { DroidType = null; } else { if ( UnitType.Type == clsUnitType.enumType.PlayerDroid ) { DroidType = (clsDroidDesign)UnitType; } else { DroidType = null; } } } if ( DroidType == null ) { ErrorCount++; } else { NewUnit = new clsUnit(); NewUnit.Type = DroidType; if ( INIDroids.Droids[A].UnitGroup == null ) { NewUnit.UnitGroup = ScavengerUnitGroup; } else { NewUnit.UnitGroup = INIDroids.Droids[A].UnitGroup; } NewUnit.Pos = INIDroids.Droids[A].Pos.WorldPos; NewUnit.Rotation = Convert.ToInt32(INIDroids.Droids[A].Rotation.Direction * 360.0D / App.INIRotationMax); if ( NewUnit.Rotation == 360 ) { NewUnit.Rotation = 0; } if ( INIDroids.Droids[A].HealthPercent >= 0 ) { NewUnit.Health = MathUtil.Clamp_dbl(INIDroids.Droids[A].HealthPercent / 100.0D, 0.01D, 1.0D); } if ( INIDroids.Droids[A].ID == 0U ) { INIDroids.Droids[A].ID = AvailableID; App.ZeroIDWarning(NewUnit, INIDroids.Droids[A].ID, ReturnResult); } UnitAdd.NewUnit = NewUnit; UnitAdd.ID = INIDroids.Droids[A].ID; UnitAdd.Perform(); App.ErrorIDChange(INIDroids.Droids[A].ID, NewUnit, "Load_WZ->INIDroids"); if ( AvailableID == INIDroids.Droids[A].ID ) { AvailableID = NewUnit.ID + 1U; } } } } if ( DroidBadPositionCount > 0 ) { ReturnResult.WarningAdd(DroidBadPositionCount + " droids had an invalid position and were removed."); } if ( UnknownDroidTypeCount > 0 ) { ReturnResult.WarningAdd(UnknownDroidTypeCount + " droid designs had an unrecognised droidType and were removed."); } if ( UnknownDroidComponentCount > 0 ) { ReturnResult.WarningAdd(UnknownDroidComponentCount + " droid designs had components that are not loaded."); } } if ( ErrorCount > 0 ) { ReturnResult.WarningAdd("Object Create Error."); } return ReturnResult; }
public App.sResult Write_FME(string Path, bool Overwrite, byte ScavengerPlayerNum) { App.sResult ReturnResult = new App.sResult(); ReturnResult.Success = false; ReturnResult.Problem = ""; if ( System.IO.File.Exists(Path) ) { if ( Overwrite ) { System.IO.File.Delete(Path); } else { ReturnResult.Problem = "The selected file already exists."; return ReturnResult; } } BinaryWriter File = null; try { File = new BinaryWriter(new FileStream(Path, FileMode.CreateNew)); int X = 0; int Z = 0; File.Write(6U); if ( Tileset == null ) { File.Write((byte)0); } else if ( Tileset == App.Tileset_Arizona ) { File.Write((byte)1); } else if ( Tileset == App.Tileset_Urban ) { File.Write((byte)2); } else if ( Tileset == App.Tileset_Rockies ) { File.Write((byte)3); } File.Write(Convert.ToBoolean((ushort)Terrain.TileSize.X)); File.Write(Convert.ToBoolean((ushort)Terrain.TileSize.Y)); byte TileAttributes = 0; byte DownSideData = 0; for ( Z = 0; Z <= Terrain.TileSize.Y; Z++ ) { for ( X = 0; X <= Terrain.TileSize.X; X++ ) { File.Write(Terrain.Vertices[X, Z].Height); if ( Terrain.Vertices[X, Z].Terrain == null ) { File.Write((byte)0); } else if ( Terrain.Vertices[X, Z].Terrain.Num < 0 ) { ReturnResult.Problem = "Terrain number out of range."; return ReturnResult; } else { File.Write(Convert.ToByte(Terrain.Vertices[X, Z].Terrain.Num + 1)); } } } for ( Z = 0; Z <= Terrain.TileSize.Y - 1; Z++ ) { for ( X = 0; X <= Terrain.TileSize.X - 1; X++ ) { File.Write(Convert.ToByte(Terrain.Tiles[X, Z].Texture.TextureNum + 1)); TileAttributes = (byte)0; if ( Terrain.Tiles[X, Z].Terrain_IsCliff ) { TileAttributes += (byte)128; } if ( Terrain.Tiles[X, Z].Texture.Orientation.SwitchedAxes ) { TileAttributes += (byte)64; } if ( Terrain.Tiles[X, Z].Texture.Orientation.ResultXFlip ) { TileAttributes += (byte)32; } if ( Terrain.Tiles[X, Z].Texture.Orientation.ResultYFlip ) { TileAttributes += (byte)16; } //8 is free if ( Terrain.Tiles[X, Z].Tri ) { TileAttributes += (byte)4; if ( Terrain.Tiles[X, Z].TriTopLeftIsCliff ) { TileAttributes += (byte)2; } if ( Terrain.Tiles[X, Z].TriBottomRightIsCliff ) { TileAttributes += (byte)1; } } else { if ( Terrain.Tiles[X, Z].TriBottomLeftIsCliff ) { TileAttributes += (byte)2; } if ( Terrain.Tiles[X, Z].TriTopRightIsCliff ) { TileAttributes += (byte)1; } } File.Write(TileAttributes); if ( TileUtil.IdenticalTileDirections(Terrain.Tiles[X, Z].DownSide, TileUtil.Top) ) { DownSideData = (byte)1; } else if ( TileUtil.IdenticalTileDirections(Terrain.Tiles[X, Z].DownSide, TileUtil.Left) ) { DownSideData = (byte)2; } else if ( TileUtil.IdenticalTileDirections(Terrain.Tiles[X, Z].DownSide, TileUtil.Right) ) { DownSideData = (byte)3; } else if ( TileUtil.IdenticalTileDirections(Terrain.Tiles[X, Z].DownSide, TileUtil.Bottom) ) { DownSideData = (byte)4; } else { DownSideData = (byte)0; } File.Write(DownSideData); } } for ( Z = 0; Z <= Terrain.TileSize.Y; Z++ ) { for ( X = 0; X <= Terrain.TileSize.X - 1; X++ ) { if ( Terrain.SideH[X, Z].Road == null ) { File.Write((byte)0); } else if ( Terrain.SideH[X, Z].Road.Num < 0 ) { ReturnResult.Problem = "Road number out of range."; return ReturnResult; } else { File.Write(Convert.ToByte(Terrain.SideH[X, Z].Road.Num + 1)); } } } for ( Z = 0; Z <= Terrain.TileSize.Y - 1; Z++ ) { for ( X = 0; X <= Terrain.TileSize.X; X++ ) { if ( Terrain.SideV[X, Z].Road == null ) { File.Write((byte)0); } else if ( Terrain.SideV[X, Z].Road.Num < 0 ) { ReturnResult.Problem = "Road number out of range."; return ReturnResult; } else { File.Write(Convert.ToByte(Terrain.SideV[X, Z].Road.Num + 1)); } } } clsUnit[] OutputUnits = new clsUnit[Units.Count]; string[] OutputUnitCode = new string[Units.Count]; int OutputUnitCount = 0; clsUnit Unit = default(clsUnit); int A = 0; foreach ( clsUnit tempLoopVar_Unit in Units ) { Unit = tempLoopVar_Unit; if ( Unit.Type.GetCode(ref OutputUnitCode[OutputUnitCount]) ) { OutputUnits[OutputUnitCount] = Unit; OutputUnitCount++; } } File.Write(Convert.ToBoolean((uint)OutputUnitCount)); for ( A = 0; A <= OutputUnitCount - 1; A++ ) { Unit = OutputUnits[A]; IOUtil.WriteTextOfLength(File, 40, OutputUnitCode[A]); switch ( Unit.Type.Type ) { case clsUnitType.enumType.Feature: File.Write((byte)0); break; case clsUnitType.enumType.PlayerStructure: File.Write((byte)1); break; case clsUnitType.enumType.PlayerDroid: File.Write((byte)2); break; } File.Write(Unit.ID); File.Write(Unit.SavePriority); File.Write(Convert.ToBoolean((uint)Unit.Pos.Horizontal.X)); File.Write(Convert.ToBoolean((uint)Unit.Pos.Horizontal.Y)); File.Write(Convert.ToBoolean((uint)Unit.Pos.Altitude)); File.Write(Convert.ToBoolean((ushort)Unit.Rotation)); IOUtil.WriteText(File, true, ""); if ( Unit.UnitGroup == ScavengerUnitGroup ) { File.Write(ScavengerPlayerNum); } else { File.Write((byte)Unit.UnitGroup.WZ_StartPos); } } File.Write(Convert.ToBoolean((uint)Gateways.Count)); clsGateway Gateway = default(clsGateway); foreach ( clsGateway tempLoopVar_Gateway in Gateways ) { Gateway = tempLoopVar_Gateway; File.Write(Convert.ToBoolean((ushort)Gateway.PosA.X)); File.Write(Convert.ToBoolean((ushort)Gateway.PosA.Y)); File.Write(Convert.ToBoolean((ushort)Gateway.PosB.X)); File.Write(Convert.ToBoolean((ushort)Gateway.PosB.Y)); } if ( Tileset != null ) { for ( A = 0; A <= Tileset.TileCount - 1; A++ ) { File.Write(Tile_TypeNum[A]); } } //scroll limits File.Write(InterfaceOptions.ScrollMin.X); File.Write(InterfaceOptions.ScrollMin.Y); File.Write(InterfaceOptions.ScrollMax.X); File.Write(InterfaceOptions.ScrollMax.Y); //other compile info IOUtil.WriteText(File, true, InterfaceOptions.CompileName); File.Write((byte)0); //multiplayer/campaign. 0 = neither IOUtil.WriteText(File, true, InterfaceOptions.CompileMultiPlayers); File.Write(InterfaceOptions.CompileMultiXPlayers); IOUtil.WriteText(File, true, InterfaceOptions.CompileMultiAuthor); IOUtil.WriteText(File, true, InterfaceOptions.CompileMultiLicense); IOUtil.WriteText(File, true, "0"); //game time int intTemp = InterfaceOptions.CampaignGameType; File.Write(intTemp); } catch ( Exception ex ) { ReturnResult.Problem = ex.Message; return ReturnResult; } if ( File != null ) { File.Close(); } ReturnResult.Success = true; return ReturnResult; }
public override clsFactoryBase getCommandFactory(clsUnit objUnit, Field FieldField) { return null; }
protected clsResult createWZObjects(List<WZBJOUnit> bjoUnits, List<IniStructure> iniStructures, List<IniDroid> iniDroids, List<IniFeature> iniFeatures) { var ReturnResult = new clsResult("Creating objects", false); logger.Info("Creating objects"); var newUnit = default(clsUnit); UInt32 availableID = 0; var unitAdd = new clsUnitAdd(); var a = 0; var b = 0; unitAdd.Map = map; availableID = 1U; foreach ( var bjoUnit in bjoUnits ) { if ( bjoUnit.ID >= availableID ) { availableID = bjoUnit.ID + 1U; } } if ( iniStructures.Count > 0) { var structMaxId = iniStructures.Max(w => w.ID) + 10; if ( structMaxId > availableID ) { availableID = structMaxId; } } if ( iniFeatures.Count > 0 ) { var featuresMaxId = iniFeatures.Max(w => w.ID) + 10; if ( featuresMaxId > availableID ) { availableID = featuresMaxId; } } if ( iniDroids.Count > 0 ) { var droidsMaxId = iniDroids.Max(w => w.ID) + 10; if ( droidsMaxId > availableID ) { availableID += droidsMaxId; } } foreach ( var bjoUnit in bjoUnits ) { newUnit = new clsUnit(); newUnit.ID = bjoUnit.ID; newUnit.TypeBase = App.ObjectData.FindOrCreateUnitType(bjoUnit.Code, bjoUnit.ObjectType, -1); if ( newUnit.TypeBase == null ) { ReturnResult.ProblemAdd("Unable to create object type."); return ReturnResult; } if ( bjoUnit.Player >= Constants.PlayerCountMax ) { newUnit.UnitGroup = map.ScavengerUnitGroup; } else { newUnit.UnitGroup = map.UnitGroups[Convert.ToInt32(bjoUnit.Player)]; } newUnit.Pos = bjoUnit.Pos; newUnit.Rotation = (int)(Math.Min(bjoUnit.Rotation, 359U)); if ( bjoUnit.ID == 0U ) { bjoUnit.ID = availableID; App.ZeroIDWarning(newUnit, bjoUnit.ID, ReturnResult); } unitAdd.NewUnit = newUnit; unitAdd.ID = bjoUnit.ID; unitAdd.Perform(); App.ErrorIDChange(bjoUnit.ID, newUnit, "CreateWZObjects"); if ( availableID == bjoUnit.ID ) { availableID = newUnit.ID + 1U; } } var structureTypeBase = default(StructureTypeBase); var droidType = default(DroidDesign); var featureTypeBase = default(FeatureTypeBase); var loadPartsArgs = new DroidDesign.sLoadPartsArgs(); UnitTypeBase unitTypeBase = null; var errorCount = 0; var unknownDroidComponentCount = 0; var unknownDroidTypeCount = 0; var droidBadPositionCount = 0; var structureBadPositionCount = 0; var structureBadModulesCount = 0; var featureBadPositionCount = 0; var moduleLimit = 0; var zeroPos = new XYInt(0, 0); var moduleTypeBase = default(StructureTypeBase); var newModule = default(clsUnit); var factoryModule = App.ObjectData.FindFirstStructureType(StructureTypeBase.enumStructureType.FactoryModule); var researchModule = App.ObjectData.FindFirstStructureType(StructureTypeBase.enumStructureType.ResearchModule); var powerModule = App.ObjectData.FindFirstStructureType(StructureTypeBase.enumStructureType.PowerModule); if ( factoryModule == null ) { ReturnResult.WarningAdd("No factory module loaded."); } if ( researchModule == null ) { ReturnResult.WarningAdd("No research module loaded."); } if ( powerModule == null ) { ReturnResult.WarningAdd("No power module loaded."); } foreach ( var iniStructure in iniStructures ) { if ( iniStructure.Pos == null ) { logger.Debug("{0} pos was null", iniStructure.Code); structureBadPositionCount++; } else if ( !App.PosIsWithinTileArea(iniStructure.Pos, zeroPos, map.Terrain.TileSize) ) { logger.Debug("{0} structure pos x{1} y{2}, is wrong.", iniStructure.Code, iniStructure.Pos.X, iniStructure.Pos.Y); structureBadPositionCount++; } else { unitTypeBase = App.ObjectData.FindOrCreateUnitType(Convert.ToString(iniStructure.Code), UnitType.PlayerStructure, iniStructure.WallType); if ( unitTypeBase.Type == UnitType.PlayerStructure ) { structureTypeBase = (StructureTypeBase)unitTypeBase; } else { structureTypeBase = null; } if ( structureTypeBase == null ) { errorCount++; } else { newUnit = new clsUnit(); newUnit.TypeBase = structureTypeBase; if ( iniStructure.UnitGroup == null ) { newUnit.UnitGroup = map.ScavengerUnitGroup; } else { newUnit.UnitGroup = iniStructure.UnitGroup; } newUnit.Pos = new WorldPos(iniStructure.Pos, iniStructure.Pos.Z); newUnit.Rotation = Convert.ToInt32(iniStructure.Rotation.Direction * 360.0D / Constants.INIRotationMax); if ( newUnit.Rotation == 360 ) { newUnit.Rotation = 0; } if ( iniStructure.HealthPercent >= 0 ) { newUnit.Health = MathUtil.Clamp_dbl(iniStructure.HealthPercent / 100.0D, 0.01D, 1.0D); } if ( iniStructure.ID == 0U ) { iniStructure.ID = availableID; App.ZeroIDWarning(newUnit, iniStructure.ID, ReturnResult); } unitAdd.NewUnit = newUnit; unitAdd.ID = iniStructure.ID; unitAdd.Perform(); App.ErrorIDChange(iniStructure.ID, newUnit, "Load_WZ->INIStructures"); if ( availableID == iniStructure.ID ) { availableID = newUnit.ID + 1U; } //create modules switch ( structureTypeBase.StructureType ) { case StructureTypeBase.enumStructureType.Factory: moduleLimit = 2; moduleTypeBase = factoryModule; break; case StructureTypeBase.enumStructureType.VTOLFactory: moduleLimit = 2; moduleTypeBase = factoryModule; break; case StructureTypeBase.enumStructureType.PowerGenerator: moduleLimit = 1; moduleTypeBase = powerModule; break; case StructureTypeBase.enumStructureType.Research: moduleLimit = 1; moduleTypeBase = researchModule; break; default: moduleLimit = 0; moduleTypeBase = null; break; } if ( iniStructure.ModuleCount > moduleLimit ) { iniStructure.ModuleCount = moduleLimit; structureBadModulesCount++; } else if ( iniStructure.ModuleCount < 0 ) { iniStructure.ModuleCount = 0; structureBadModulesCount++; } if ( moduleTypeBase != null ) { for ( b = 0; b <= iniStructure.ModuleCount - 1; b++ ) { newModule = new clsUnit(); newModule.TypeBase = moduleTypeBase; newModule.UnitGroup = newUnit.UnitGroup; newModule.Pos = newUnit.Pos; newModule.Rotation = newUnit.Rotation; unitAdd.NewUnit = newModule; unitAdd.ID = availableID; unitAdd.Perform(); availableID = newModule.ID + 1U; } } } } } if ( structureBadPositionCount > 0 ) { ReturnResult.WarningAdd(structureBadPositionCount + " structures had an invalid position and were removed."); } if ( structureBadModulesCount > 0 ) { ReturnResult.WarningAdd(structureBadModulesCount + " structures had an invalid number of modules."); } foreach ( var iniFeature in iniFeatures ) { if ( iniFeature.Pos == null ) { featureBadPositionCount++; } else if ( !App.PosIsWithinTileArea(iniFeature.Pos, zeroPos, map.Terrain.TileSize) ) { featureBadPositionCount++; } else { unitTypeBase = App.ObjectData.FindOrCreateUnitType(Convert.ToString(iniFeature.Code), UnitType.Feature, -1); if ( unitTypeBase.Type == UnitType.Feature ) { featureTypeBase = (FeatureTypeBase)unitTypeBase; } else { featureTypeBase = null; } if ( featureTypeBase == null ) { errorCount++; } else { newUnit = new clsUnit(); newUnit.TypeBase = featureTypeBase; newUnit.UnitGroup = map.ScavengerUnitGroup; newUnit.Pos = new WorldPos(iniFeature.Pos, iniFeature.Pos.Z); newUnit.Rotation = Convert.ToInt32(iniFeature.Rotation.Direction * 360.0D / Constants.INIRotationMax); if ( newUnit.Rotation == 360 ) { newUnit.Rotation = 0; } if ( iniFeature.HealthPercent >= 0 ) { newUnit.Health = MathUtil.Clamp_dbl(iniFeature.HealthPercent / 100.0D, 0.01D, 1.0D); } if ( iniFeature.ID == 0U ) { iniFeature.ID = availableID; App.ZeroIDWarning(newUnit, iniFeature.ID, ReturnResult); } unitAdd.NewUnit = newUnit; unitAdd.ID = iniFeature.ID; unitAdd.Perform(); App.ErrorIDChange(iniFeature.ID, newUnit, "Load_WZ->INIFeatures"); if ( availableID == iniFeature.ID ) { availableID = newUnit.ID + 1U; } } } } if ( featureBadPositionCount > 0 ) { ReturnResult.WarningAdd(featureBadPositionCount + " features had an invalid position and were removed."); } foreach ( var iniDroid in iniDroids ) { if ( iniDroid.Pos == null ) { droidBadPositionCount++; } else if ( !App.PosIsWithinTileArea(iniDroid.Pos, zeroPos, map.Terrain.TileSize) ) { droidBadPositionCount++; } else { if ( iniDroid.Template == null || iniDroid.Template == "" ) { droidType = new DroidDesign(); if ( !droidType.SetDroidType((enumDroidType)(iniDroid.DroidType)) ) { unknownDroidTypeCount++; } loadPartsArgs.Body = App.ObjectData.FindOrCreateBody(iniDroid.Body); if ( loadPartsArgs.Body == null ) { unknownDroidComponentCount++; } else { if ( loadPartsArgs.Body.IsUnknown ) { unknownDroidComponentCount++; } } loadPartsArgs.Propulsion = App.ObjectData.FindOrCreatePropulsion(Convert.ToString(iniDroid.Propulsion)); if ( loadPartsArgs.Propulsion == null ) { unknownDroidComponentCount++; } else { if ( loadPartsArgs.Propulsion.IsUnknown ) { unknownDroidComponentCount++; } } loadPartsArgs.Construct = App.ObjectData.FindOrCreateConstruct(Convert.ToString(iniDroid.Construct)); if ( loadPartsArgs.Construct == null ) { unknownDroidComponentCount++; } else { if ( loadPartsArgs.Construct.IsUnknown ) { unknownDroidComponentCount++; } } loadPartsArgs.Repair = App.ObjectData.FindOrCreateRepair(iniDroid.Repair); if ( loadPartsArgs.Repair == null ) { unknownDroidComponentCount++; } else { if ( loadPartsArgs.Repair.IsUnknown ) { unknownDroidComponentCount++; } } loadPartsArgs.Sensor = App.ObjectData.FindOrCreateSensor(iniDroid.Sensor); if ( loadPartsArgs.Sensor == null ) { unknownDroidComponentCount++; } else { if ( loadPartsArgs.Sensor.IsUnknown ) { unknownDroidComponentCount++; } } loadPartsArgs.Brain = App.ObjectData.FindOrCreateBrain(iniDroid.Brain); if ( loadPartsArgs.Brain == null ) { unknownDroidComponentCount++; } else { if ( loadPartsArgs.Brain.IsUnknown ) { unknownDroidComponentCount++; } } loadPartsArgs.ECM = App.ObjectData.FindOrCreateECM(Convert.ToString(iniDroid.ECM)); if ( loadPartsArgs.ECM == null ) { unknownDroidComponentCount++; } else { if ( loadPartsArgs.ECM.IsUnknown ) { unknownDroidComponentCount++; } } loadPartsArgs.Weapon1 = App.ObjectData.FindOrCreateWeapon(Convert.ToString(iniDroid.Weapons[0])); if ( loadPartsArgs.Weapon1 == null ) { unknownDroidComponentCount++; } else { if ( loadPartsArgs.Weapon1.IsUnknown ) { unknownDroidComponentCount++; } } loadPartsArgs.Weapon2 = App.ObjectData.FindOrCreateWeapon(Convert.ToString(iniDroid.Weapons[1])); if ( loadPartsArgs.Weapon2 == null ) { unknownDroidComponentCount++; } else { if ( loadPartsArgs.Weapon2.IsUnknown ) { unknownDroidComponentCount++; } } loadPartsArgs.Weapon3 = App.ObjectData.FindOrCreateWeapon(Convert.ToString(iniDroid.Weapons[2])); if ( loadPartsArgs.Weapon3 == null ) { unknownDroidComponentCount++; } else { if ( loadPartsArgs.Weapon3.IsUnknown ) { unknownDroidComponentCount++; } } droidType.LoadParts(loadPartsArgs); } else { unitTypeBase = App.ObjectData.FindOrCreateUnitType(iniDroid.Template, UnitType.PlayerDroid, -1); if ( unitTypeBase == null ) { droidType = null; } else { if ( unitTypeBase.Type == UnitType.PlayerDroid ) { droidType = (DroidDesign)unitTypeBase; } else { droidType = null; } } } if ( droidType == null ) { errorCount++; } else { newUnit = new clsUnit(); newUnit.TypeBase = droidType; if ( iniDroid.UnitGroup == null ) { newUnit.UnitGroup = map.ScavengerUnitGroup; } else { newUnit.UnitGroup = iniDroid.UnitGroup; } newUnit.Pos = new WorldPos(iniDroid.Pos, iniDroid.Pos.Z); newUnit.Rotation = Convert.ToInt32(iniDroid.Rotation.Direction * 360.0D / Constants.INIRotationMax); if ( newUnit.Rotation == 360 ) { newUnit.Rotation = 0; } if ( iniDroid.HealthPercent >= 0 ) { newUnit.Health = MathUtil.Clamp_dbl(iniDroid.HealthPercent / 100.0D, 0.01D, 1.0D); } if ( iniDroid.ID == 0U ) { iniDroid.ID = availableID; App.ZeroIDWarning(newUnit, iniDroid.ID, ReturnResult); } unitAdd.NewUnit = newUnit; unitAdd.ID = iniDroid.ID; unitAdd.Perform(); App.ErrorIDChange(iniDroid.ID, newUnit, "Load_WZ->INIDroids"); if ( availableID == iniDroid.ID ) { availableID = newUnit.ID + 1U; } } } } if ( droidBadPositionCount > 0 ) { ReturnResult.WarningAdd(droidBadPositionCount + " droids had an invalid position and were removed."); } if ( unknownDroidTypeCount > 0 ) { ReturnResult.WarningAdd(unknownDroidTypeCount + " droid designs had an unrecognised droidType and were removed."); } if ( unknownDroidComponentCount > 0 ) { ReturnResult.WarningAdd(unknownDroidComponentCount + " droid designs had components that are not loaded."); } if ( errorCount > 0 ) { ReturnResult.WarningAdd("Object Create Error."); } return ReturnResult; }
public void PerformTileWall(clsWallType WallType, sXY_int TileNum, bool Expand) { sXY_int SectorNum = new sXY_int(); clsUnit Unit = default(clsUnit); sXY_int UnitTile = new sXY_int(); sXY_int Difference = new sXY_int(); App.enumTileWalls TileWalls = App.enumTileWalls.None; SimpleList<clsUnit> Walls = new SimpleList<clsUnit>(); SimpleList<clsUnit> Removals = new SimpleList<clsUnit>(); clsUnitType UnitType = default(clsUnitType); clsStructureType StructureType = default(clsStructureType); int X = 0; int Y = 0; sXY_int MinTile = new sXY_int(); sXY_int MaxTile = new sXY_int(); clsUnitSectorConnection Connection = default(clsUnitSectorConnection); MinTile.X = TileNum.X - 1; MinTile.Y = TileNum.Y - 1; MaxTile.X = TileNum.X + 1; MaxTile.Y = TileNum.Y + 1; sXY_int SectorStart = GetSectorNumClamped(GetTileSectorNum(MinTile)); sXY_int SectorFinish = GetSectorNumClamped(GetTileSectorNum(MaxTile)); for ( Y = SectorStart.Y; Y <= SectorFinish.Y; Y++ ) { for ( X = SectorStart.X; X <= SectorFinish.X; X++ ) { SectorNum.X = X; SectorNum.Y = Y; foreach ( clsUnitSectorConnection tempLoopVar_Connection in Sectors[SectorNum.X, SectorNum.Y].Units ) { Connection = tempLoopVar_Connection; Unit = Connection.Unit; UnitType = Unit.Type; if ( UnitType.Type == clsUnitType.enumType.PlayerStructure ) { StructureType = (clsStructureType)UnitType; if ( StructureType.WallLink.Source == WallType ) { UnitTile = GetPosTileNum(Unit.Pos.Horizontal); Difference.X = UnitTile.X - TileNum.X; Difference.Y = UnitTile.Y - TileNum.Y; if ( Difference.Y == 1 ) { if ( Difference.X == 0 ) { TileWalls = (App.enumTileWalls)(TileWalls | App.enumTileWalls.Bottom); Walls.Add(Unit); } } else if ( Difference.Y == 0 ) { if ( Difference.X == 0 ) { Removals.Add(Unit); } else if ( Difference.X == -1 ) { TileWalls = (App.enumTileWalls)(TileWalls | App.enumTileWalls.Left); Walls.Add(Unit); } else if ( Difference.X == 1 ) { TileWalls = (App.enumTileWalls)(TileWalls | App.enumTileWalls.Right); Walls.Add(Unit); } } else if ( Difference.Y == -1 ) { if ( Difference.X == 0 ) { TileWalls = (App.enumTileWalls)(TileWalls | App.enumTileWalls.Top); Walls.Add(Unit); } } } } } } } foreach ( clsUnit tempLoopVar_Unit in Removals ) { Unit = tempLoopVar_Unit; UnitRemoveStoreChange(Unit.MapLink.ArrayPosition); } clsUnit NewUnit = new clsUnit(); clsUnitType NewUnitType = WallType.Segments[WallType.TileWalls_Segment[(int)TileWalls]]; NewUnit.Rotation = WallType.TileWalls_Direction[(int)TileWalls]; if ( Expand ) { NewUnit.UnitGroup = SelectedUnitGroup.Item; } else { if ( Removals.Count == 0 ) { Debugger.Break(); return; } NewUnit.UnitGroup = Removals[0].UnitGroup; } NewUnit.Pos = TileAlignedPos(TileNum, new sXY_int(1, 1)); NewUnit.Type = NewUnitType; clsUnitAdd UnitAdd = new clsUnitAdd(); UnitAdd.Map = this; UnitAdd.NewUnit = NewUnit; UnitAdd.StoreChange = true; UnitAdd.Perform(); if ( Expand ) { clsUnit Wall = default(clsUnit); foreach ( clsUnit tempLoopVar_Wall in Walls ) { Wall = tempLoopVar_Wall; PerformTileWall(WallType, GetPosTileNum(Wall.Pos.Horizontal), false); } } }
public clsResult Load(string path) { var returnResult = new clsResult("Loading LND from \"{0}\"".Format2(path), false); logger.Info("Loading LND from \"{0}\"".Format2(path)); try { var strTemp = ""; var strTemp2 = ""; var X = 0; var Y = 0; var A = 0; var B = 0; var Tile_Num = 0; // SimpleList<string> LineData = default(SimpleList<string>); var Line_Num = 0; LNDTile[] LNDTile = null; var LNDObjects = new SimpleList<LNDObject>(); var UnitAdd = new clsUnitAdd(); UnitAdd.Map = map; var Reader = default(BinaryReader); try { Reader = new BinaryReader(new FileStream(path, FileMode.Open), App.UTF8Encoding); } catch ( Exception ex ) { returnResult.ProblemAdd(ex.Message); return returnResult; } var LineData = IOUtil.BytesToLinesRemoveComments(Reader); Reader.Close(); Array.Resize(ref LNDTile, LineData.Count); var strTemp3 = ""; var GotTiles = default(bool); var GotObjects = default(bool); var GotGates = default(bool); var GotTileTypes = default(bool); var LNDTileType = new byte[0]; var ObjectText = new string[11]; var GateText = new string[4]; var TileTypeText = new string[256]; var LNDTileTypeCount = 0; var LNDGates = new SimpleList<clsGateway>(); var Gateway = default(clsGateway); var C = 0; var D = 0; var GotText = default(bool); var FlipX = default(bool); var FlipZ = default(bool); byte Rotation = 0; var NewTileSize = new XYInt(); double dblTemp = 0; Line_Num = 0; while ( Line_Num < LineData.Count ) { strTemp = LineData[Line_Num]; A = strTemp.IndexOf("TileWidth ") + 1; if ( A == 0 ) { } A = strTemp.IndexOf("TileHeight ") + 1; if ( A == 0 ) { } A = strTemp.IndexOf("MapWidth ") + 1; if ( A == 0 ) { } else { IOUtil.InvariantParse(strTemp.Substring(strTemp.Length - (strTemp.Length - (A + 8)), strTemp.Length - (A + 8)), ref NewTileSize.X); goto LineDone; } A = strTemp.IndexOf("MapHeight ") + 1; if ( A == 0 ) { } else { IOUtil.InvariantParse(strTemp.Substring(strTemp.Length - (strTemp.Length - (A + 9)), strTemp.Length - (A + 9)), ref NewTileSize.Y); goto LineDone; } A = strTemp.IndexOf("Textures {") + 1; if ( A == 0 ) { } else { Line_Num++; strTemp = LineData[Line_Num]; strTemp2 = strTemp.ToLower(); if ( strTemp2.IndexOf("tertilesc1") + 1 > 0 ) { map.Tileset = App.Tileset_Arizona; } if ( strTemp2.IndexOf("tertilesc2") + 1 > 0 ) { map.Tileset = App.Tileset_Urban; } if ( strTemp2.IndexOf("tertilesc3") + 1 > 0 ) { map.Tileset = App.Tileset_Rockies; } goto LineDone; } A = strTemp.IndexOf("Tiles {") + 1; if ( A == 0 || GotTiles ) { } else { Line_Num++; while ( Line_Num < LineData.Count ) { strTemp = LineData[Line_Num]; A = strTemp.IndexOf("}") + 1; if ( A == 0 ) { A = strTemp.IndexOf("TID ") + 1; if ( A == 0 ) { returnResult.ProblemAdd("Tile ID missing"); return returnResult; } strTemp2 = strTemp.Substring(strTemp.Length - (strTemp.Length - A - 3), strTemp.Length - A - 3); A = strTemp2.IndexOf(" ") + 1; if ( A > 0 ) { strTemp2 = strTemp2.Substring(0, A - 1); } var temp_Result = LNDTile[Tile_Num].TID; IOUtil.InvariantParse(strTemp2, ref temp_Result); A = strTemp.IndexOf("VF ") + 1; if ( A == 0 ) { returnResult.ProblemAdd("Tile VF missing"); return returnResult; } strTemp2 = strTemp.Substring(strTemp.Length - (strTemp.Length - A - 2), strTemp.Length - A - 2); A = strTemp2.IndexOf(" ") + 1; if ( A > 0 ) { strTemp2 = strTemp2.Substring(0, A - 1); } var temp_Result2 = LNDTile[Tile_Num].VF; IOUtil.InvariantParse(strTemp2, ref temp_Result2); A = strTemp.IndexOf("TF ") + 1; if ( A == 0 ) { returnResult.ProblemAdd("Tile TF missing"); return returnResult; } strTemp2 = strTemp.Substring(strTemp.Length - (strTemp.Length - A - 2), strTemp.Length - A - 2); A = strTemp2.IndexOf(" ") + 1; if ( A > 0 ) { strTemp2 = strTemp2.Substring(0, A - 1); } var temp_Result3 = LNDTile[Tile_Num].TF; IOUtil.InvariantParse(strTemp2, ref temp_Result3); A = strTemp.IndexOf(" F ") + 1; if ( A == 0 ) { returnResult.ProblemAdd("Tile flip missing"); return returnResult; } strTemp2 = strTemp.Substring(strTemp.Length - A - 2, strTemp.Length - A - 2); A = strTemp2.IndexOf(" "); if ( A > 0 ) { strTemp2 = strTemp2.Substring(0, A); } var temp_Result4 = LNDTile[Tile_Num].F; IOUtil.InvariantParse(strTemp2, ref temp_Result4); A = strTemp.IndexOf(" VH ") + 1; if ( A == 0 ) { returnResult.ProblemAdd("Tile height is missing"); return returnResult; } strTemp3 = strTemp.Substring(strTemp.Length - (strTemp.Length - A - 3), strTemp.Length - A - 3); for ( A = 0; A <= 2; A++ ) { B = strTemp3.IndexOf(" ") + 1; if ( B == 0 ) { returnResult.ProblemAdd("A tile height value is missing"); return returnResult; } strTemp2 = strTemp3.Substring(0, B - 1); strTemp3 = strTemp3.Substring(strTemp3.Length - (strTemp3.Length - B), strTemp3.Length - B); if ( A == 0 ) { var temp_Result5 = LNDTile[Tile_Num].Vertex0Height; IOUtil.InvariantParse(strTemp2, ref temp_Result5); } else if ( A == 1 ) { var temp_Result6 = LNDTile[Tile_Num].Vertex1Height; IOUtil.InvariantParse(strTemp2, ref temp_Result6); } else if ( A == 2 ) { var temp_Result7 = LNDTile[Tile_Num].Vertex2Height; IOUtil.InvariantParse(strTemp2, ref temp_Result7); } } var temp_Result8 = LNDTile[Tile_Num].Vertex3Height; IOUtil.InvariantParse(strTemp3, ref temp_Result8); Tile_Num++; } else { GotTiles = true; goto LineDone; } Line_Num++; } GotTiles = true; goto LineDone; } A = strTemp.IndexOf("Objects {") + 1; if ( A == 0 || GotObjects ) { } else { Line_Num++; while ( Line_Num < LineData.Count ) { strTemp = LineData[Line_Num]; A = strTemp.IndexOf("}") + 1; if ( A == 0 ) { C = 0; ObjectText[0] = ""; GotText = false; for ( B = 0; B <= strTemp.Length - 1; B++ ) { if ( strTemp[B] != ' ' && strTemp[B] != '\t' ) { GotText = true; ObjectText[C] += strTemp[B].ToString(); } else { if ( GotText ) { C++; if ( C == 11 ) { returnResult.ProblemAdd("Too many fields for an object, or a space at the end."); return returnResult; } ObjectText[C] = ""; GotText = false; } } } var NewObject = new LNDObject(); IOUtil.InvariantParse(ObjectText[0], ref NewObject.ID); IOUtil.InvariantParse(ObjectText[1], ref NewObject.TypeNum); NewObject.Code = ObjectText[2].Substring(1, ObjectText[2].Length - 2); //remove quotes IOUtil.InvariantParse(ObjectText[3], ref NewObject.PlayerNum); NewObject.Name = ObjectText[4].Substring(1, ObjectText[4].Length - 2); //remove quotes IOUtil.InvariantParse(ObjectText[5], ref NewObject.Pos.X); IOUtil.InvariantParse(ObjectText[6], ref NewObject.Pos.Y); IOUtil.InvariantParse(ObjectText[7], ref NewObject.Pos.Z); if ( IOUtil.InvariantParse(ObjectText[8], ref dblTemp) ) { NewObject.Rotation.X = (int)(MathUtil.Clamp_dbl(dblTemp, 0.0D, 359.0D)); } if ( IOUtil.InvariantParse(ObjectText[9], ref dblTemp) ) { NewObject.Rotation.Y = (int)(MathUtil.Clamp_dbl(dblTemp, 0.0D, 359.0D)); } if ( IOUtil.InvariantParse(ObjectText[10], ref dblTemp) ) { NewObject.Rotation.Z = (int)(MathUtil.Clamp_dbl(dblTemp, 0.0D, 359.0D)); } LNDObjects.Add(NewObject); } else { GotObjects = true; goto LineDone; } Line_Num++; } GotObjects = true; goto LineDone; } A = strTemp.IndexOf("Gates {") + 1; if ( A == 0 || GotGates ) { } else { Line_Num++; while ( Line_Num < LineData.Count ) { strTemp = LineData[Line_Num]; A = strTemp.IndexOf("}") + 1; if ( A == 0 ) { C = 0; GateText[0] = ""; GotText = false; for ( B = 0; B <= strTemp.Length - 1; B++ ) { if ( strTemp[B] != ' ' && strTemp[B] != '\t' ) { GotText = true; GateText[C] += strTemp[B].ToString(); } else { if ( GotText ) { C++; if ( C == 4 ) { returnResult.ProblemAdd("Too many fields for a gateway, or a space at the end."); return returnResult; } GateText[C] = ""; GotText = false; } } } Gateway = new clsGateway(); IOUtil.InvariantParse(GateText[0], ref Gateway.PosA.X); Gateway.PosA.X = Math.Max(Gateway.PosA.X, 0); IOUtil.InvariantParse(GateText[1], ref Gateway.PosA.Y); Gateway.PosA.Y = Math.Max(Gateway.PosA.Y, 0); IOUtil.InvariantParse(GateText[2], ref Gateway.PosB.X); Gateway.PosB.X = Math.Max(Gateway.PosB.X, 0); IOUtil.InvariantParse(GateText[3], ref Gateway.PosB.Y); Gateway.PosB.Y = Math.Max(Gateway.PosB.Y, 0); LNDGates.Add(Gateway); } else { GotGates = true; goto LineDone; } Line_Num++; } GotGates = true; goto LineDone; } A = strTemp.IndexOf("Tiles {") + 1; if ( A == 0 || GotTileTypes || !GotTiles ) { } else { Line_Num++; while ( Line_Num < LineData.Count ) { strTemp = LineData[Line_Num]; A = strTemp.IndexOf("}") + 1; if ( A == 0 ) { C = 0; TileTypeText[0] = ""; GotText = false; for ( B = 0; B <= strTemp.Length - 1; B++ ) { if ( strTemp[B] != ' ' && strTemp[B] != '\t' ) { GotText = true; TileTypeText[C] += strTemp[B].ToString(); } else { if ( GotText ) { C++; if ( C == 256 ) { returnResult.ProblemAdd("Too many fields for tile types."); return returnResult; } TileTypeText[C] = ""; GotText = false; } } } if ( TileTypeText[C] == "" || TileTypeText[C] == " " ) { C--; } for ( D = 0; D <= C; D++ ) { Array.Resize(ref LNDTileType, LNDTileTypeCount + 1); LNDTileType[LNDTileTypeCount] = Math.Min(byte.Parse(TileTypeText[D]), (byte)11); LNDTileTypeCount++; } } else { GotTileTypes = true; goto LineDone; } Line_Num++; } GotTileTypes = true; } LineDone: Line_Num++; } Array.Resize(ref LNDTile, Tile_Num); map.SetPainterToDefaults(); if ( NewTileSize.X < 1 | NewTileSize.Y < 1 ) { returnResult.ProblemAdd("The LND\'s terrain dimensions are missing or invalid."); return returnResult; } map.TerrainBlank(NewTileSize); map.TileType_Reset(); for ( Y = 0; Y <= map.Terrain.TileSize.Y - 1; Y++ ) { for ( X = 0; X <= map.Terrain.TileSize.X - 1; X++ ) { Tile_Num = Y * map.Terrain.TileSize.X + X; //lnd uses different order! (3 = 2, 2 = 3), this program goes left to right, lnd goes clockwise around each tile map.Terrain.Vertices[X, Y].Height = (byte)(LNDTile[Tile_Num].Vertex0Height); } } for ( Y = 0; Y <= map.Terrain.TileSize.Y - 1; Y++ ) { for ( X = 0; X <= map.Terrain.TileSize.X - 1; X++ ) { Tile_Num = Y * map.Terrain.TileSize.X + X; map.Terrain.Tiles[X, Y].Texture.TextureNum = LNDTile[Tile_Num].TID - 1; //ignore higher values A = Convert.ToInt32((LNDTile[Tile_Num].F / 64.0D)); LNDTile[Tile_Num].F = (short)(LNDTile[Tile_Num].F - A * 64); A = (int)((LNDTile[Tile_Num].F / 16.0D)); LNDTile[Tile_Num].F = (short)(LNDTile[Tile_Num].F - A * 16); if ( A < 0 | A > 3 ) { returnResult.ProblemAdd("Invalid flip value."); return returnResult; } Rotation = (byte)A; A = (int)((LNDTile[Tile_Num].F / 8.0D)); LNDTile[Tile_Num].F -= (short)(A * 8); FlipZ = A == 1; A = (int)((LNDTile[Tile_Num].F / 4.0D)); LNDTile[Tile_Num].F -= (short)(A * 4); FlipX = A == 1; A = Convert.ToInt32((LNDTile[Tile_Num].F / 2.0D)); LNDTile[Tile_Num].F -= (short)(A * 2); map.Terrain.Tiles[X, Y].Tri = A == 1; //vf, tf, ignore TileUtil.OldOrientation_To_TileOrientation(Rotation, FlipX, FlipZ, ref map.Terrain.Tiles[X, Y].Texture.Orientation); } } var newUnit = default(clsUnit); var xyzInt = new XYZInt(0, 0, 0); var newTypeBase = default(UnitTypeBase); UInt32 availableID = 0; availableID = 1U; foreach ( var currentObject in LNDObjects ) { if ( currentObject.ID >= availableID ) { availableID = currentObject.ID + 1U; } } foreach ( var currentObject in LNDObjects ) { switch ( currentObject.TypeNum ) { case 0: newTypeBase = App.ObjectData.FindOrCreateUnitType(currentObject.Code, UnitType.Feature, -1); break; case 1: newTypeBase = App.ObjectData.FindOrCreateUnitType(currentObject.Code, UnitType.PlayerStructure, -1); break; case 2: newTypeBase = App.ObjectData.FindOrCreateUnitType(currentObject.Code, UnitType.PlayerDroid, -1); break; default: newTypeBase = null; break; } if ( newTypeBase != null ) { newUnit = new clsUnit(); newUnit.TypeBase = newTypeBase; if ( currentObject.PlayerNum < 0 | currentObject.PlayerNum >= Constants.PlayerCountMax ) { newUnit.UnitGroup = map.ScavengerUnitGroup; } else { newUnit.UnitGroup = map.UnitGroups[currentObject.PlayerNum]; } xyzInt.X = (int)currentObject.Pos.X; xyzInt.Y = (int)currentObject.Pos.Y; xyzInt.Z = (int)currentObject.Pos.Z; newUnit.Pos = mapPos_From_LNDPos(xyzInt); newUnit.Rotation = currentObject.Rotation.Y; if ( currentObject.ID == 0U ) { currentObject.ID = availableID; App.ZeroIDWarning(newUnit, currentObject.ID, returnResult); } UnitAdd.NewUnit = newUnit; UnitAdd.ID = currentObject.ID; UnitAdd.Perform(); App.ErrorIDChange(currentObject.ID, newUnit, "Load_LND"); if ( availableID == currentObject.ID ) { availableID = newUnit.ID + 1U; } } } foreach ( var tempLoopVar_Gateway in LNDGates ) { Gateway = tempLoopVar_Gateway; map.GatewayCreate(Gateway.PosA, Gateway.PosB); } if ( map.Tileset != null ) { for ( A = 0; A <= Math.Min(LNDTileTypeCount - 1, map.Tileset.TileCount) - 1; A++ ) { map.Tile_TypeNum[A] = LNDTileType[A + 1]; //lnd value 0 is ignored } } } catch ( Exception ex ) { returnResult.ProblemAdd(ex.Message); return returnResult; } return returnResult; }
private void UnitSectorsGraphicsChanged(clsUnit UnitToUpdateFor) { if ( SectorGraphicsChanges == null ) { Debugger.Break(); return; } clsUnitSectorConnection Connection = default(clsUnitSectorConnection); foreach ( clsUnitSectorConnection tempLoopVar_Connection in UnitToUpdateFor.Sectors ) { Connection = tempLoopVar_Connection; SectorGraphicsChanges.Changed(Connection.Sector.Pos); } }
private clsResult Read_FME(BinaryReader File) { clsResult ReturnResult = new clsResult("Reading FME"); UInt32 Version = 0; clsInterfaceOptions ResultInfo = new clsInterfaceOptions(); clsUnitAdd UnitAdd = new clsUnitAdd(); UnitAdd.Map = this; try { Version = File.ReadUInt32(); if ( Version <= 4U ) { ReturnResult.ProblemAdd("Version " + Convert.ToString(Version) + " is not supported."); return ReturnResult; } else if ( Version == 5U || Version == 6U || Version == 7U ) { byte byteTemp = 0; //tileset byteTemp = File.ReadByte(); if ( byteTemp == 0 ) { Tileset = null; } else if ( byteTemp == 1 ) { Tileset = App.Tileset_Arizona; } else if ( byteTemp == 2 ) { Tileset = App.Tileset_Urban; } else if ( byteTemp == 3 ) { Tileset = App.Tileset_Rockies; } else { ReturnResult.WarningAdd("Tileset value out of range."); Tileset = null; } SetPainterToDefaults(); //depends on tileset. must be called before loading the terrains. UInt16 MapWidth = 0; UInt16 MapHeight = 0; MapWidth = File.ReadUInt16(); MapHeight = File.ReadUInt16(); if ( MapWidth < 1U || MapHeight < 1U || MapWidth > Constants.MapMaxSize || MapHeight > Constants.MapMaxSize ) { ReturnResult.ProblemAdd("Map size is invalid."); return ReturnResult; } TerrainBlank(new sXY_int(MapWidth, MapHeight)); TileType_Reset(); int X = 0; int Y = 0; int A = 0; int B = 0; int intTemp = 0; int WarningCount = 0; WarningCount = 0; for ( Y = 0; Y <= Terrain.TileSize.Y; Y++ ) { for ( X = 0; X <= Terrain.TileSize.X; X++ ) { Terrain.Vertices[X, Y].Height = File.ReadByte(); byteTemp = File.ReadByte(); intTemp = (byteTemp) - 1; if ( intTemp < 0 ) { Terrain.Vertices[X, Y].Terrain = null; } else if ( intTemp >= Painter.TerrainCount ) { WarningCount++; Terrain.Vertices[X, Y].Terrain = null; } else { Terrain.Vertices[X, Y].Terrain = Painter.Terrains[intTemp]; } } } if ( WarningCount > 0 ) { ReturnResult.WarningAdd(WarningCount + " painted ground vertices were out of range."); } WarningCount = 0; for ( Y = 0; Y <= Terrain.TileSize.Y - 1; Y++ ) { for ( X = 0; X <= Terrain.TileSize.X - 1; X++ ) { byteTemp = File.ReadByte(); Terrain.Tiles[X, Y].Texture.TextureNum = (byteTemp) - 1; byteTemp = File.ReadByte(); intTemp = 128; A = (int)(Conversion.Int(byteTemp / intTemp)); byteTemp -= (byte)(A * intTemp); Terrain.Tiles[X, Y].Terrain_IsCliff = A == 1; intTemp = 64; A = (int)(Conversion.Int(byteTemp / intTemp)); byteTemp -= (byte)(A * intTemp); Terrain.Tiles[X, Y].Texture.Orientation.SwitchedAxes = A == 1; intTemp = 32; A = (int)(Conversion.Int(byteTemp / intTemp)); byteTemp -= (byte)(A * intTemp); Terrain.Tiles[X, Y].Texture.Orientation.ResultXFlip = A == 1; intTemp = 16; A = (int)(Conversion.Int(byteTemp / intTemp)); byteTemp -= (byte)(A * intTemp); Terrain.Tiles[X, Y].Texture.Orientation.ResultYFlip = A == 1; intTemp = 4; A = (int)(Conversion.Int(byteTemp / intTemp)); byteTemp -= (byte)(A * intTemp); Terrain.Tiles[X, Y].Tri = A == 1; intTemp = 2; A = (int)(Conversion.Int(byteTemp / intTemp)); byteTemp -= (byte)(A * intTemp); if ( Terrain.Tiles[X, Y].Tri ) { Terrain.Tiles[X, Y].TriTopLeftIsCliff = A == 1; } else { Terrain.Tiles[X, Y].TriBottomLeftIsCliff = A == 1; } intTemp = 1; A = (int)(Conversion.Int(byteTemp / intTemp)); byteTemp -= (byte)(A * intTemp); if ( Terrain.Tiles[X, Y].Tri ) { Terrain.Tiles[X, Y].TriBottomRightIsCliff = A == 1; } else { Terrain.Tiles[X, Y].TriTopRightIsCliff = A == 1; } //attributes2 byteTemp = File.ReadByte(); if ( byteTemp == ((byte)0) ) { Terrain.Tiles[X, Y].DownSide = TileUtil.None; } else if ( byteTemp == ((byte)1) ) { Terrain.Tiles[X, Y].DownSide = TileUtil.Top; } else if ( byteTemp == ((byte)2) ) { Terrain.Tiles[X, Y].DownSide = TileUtil.Left; } else if ( byteTemp == ((byte)3) ) { Terrain.Tiles[X, Y].DownSide = TileUtil.Right; } else if ( byteTemp == ((byte)4) ) { Terrain.Tiles[X, Y].DownSide = TileUtil.Bottom; } else { WarningCount++; } } } if ( WarningCount > 0 ) { ReturnResult.WarningAdd(WarningCount + " tile cliff down-sides were out of range."); } WarningCount = 0; for ( Y = 0; Y <= Terrain.TileSize.Y; Y++ ) { for ( X = 0; X <= Terrain.TileSize.X - 1; X++ ) { byteTemp = File.ReadByte(); intTemp = (byteTemp) - 1; if ( intTemp < 0 ) { Terrain.SideH[X, Y].Road = null; } else if ( intTemp >= Painter.RoadCount ) { WarningCount++; Terrain.SideH[X, Y].Road = null; } else { Terrain.SideH[X, Y].Road = Painter.Roads[intTemp]; } } } for ( Y = 0; Y <= Terrain.TileSize.Y - 1; Y++ ) { for ( X = 0; X <= Terrain.TileSize.X; X++ ) { byteTemp = File.ReadByte(); intTemp = (byteTemp) - 1; if ( intTemp < 0 ) { Terrain.SideV[X, Y].Road = null; } else if ( intTemp >= Painter.RoadCount ) { WarningCount++; Terrain.SideV[X, Y].Road = null; } else { Terrain.SideV[X, Y].Road = Painter.Roads[intTemp]; } } } if ( WarningCount > 0 ) { ReturnResult.WarningAdd(WarningCount + " roads were out of range."); } UInt32 TempUnitCount = 0; TempUnitCount = File.ReadUInt32(); sFMEUnit[] TempUnit = new sFMEUnit[(Convert.ToInt32(TempUnitCount))]; for ( A = 0; A <= (Convert.ToInt32(TempUnitCount)) - 1; A++ ) { TempUnit[A].Code = new string(File.ReadChars(40)); B = Strings.InStr(TempUnit[A].Code, Convert.ToString('\0'), (CompareMethod)0); if ( B > 0 ) { TempUnit[A].Code = Strings.Left(TempUnit[A].Code, B - 1); } TempUnit[A].LNDType = File.ReadByte(); TempUnit[A].ID = File.ReadUInt32(); if ( Version == 6U ) { TempUnit[A].SavePriority = File.ReadInt32(); } TempUnit[A].X = File.ReadUInt32(); TempUnit[A].Z = File.ReadUInt32(); TempUnit[A].Y = File.ReadUInt32(); TempUnit[A].Rotation = File.ReadUInt16(); TempUnit[A].Name = IOUtil.ReadOldText(File); TempUnit[A].Player = File.ReadByte(); } clsUnit NewUnit = default(clsUnit); clsUnitType UnitType = null; UInt32 AvailableID = 0; AvailableID = 1U; for ( A = 0; A <= (Convert.ToInt32(TempUnitCount)) - 1; A++ ) { if ( TempUnit[A].ID >= AvailableID ) { AvailableID = TempUnit[A].ID + 1U; } } WarningCount = 0; for ( A = 0; A <= (Convert.ToInt32(TempUnitCount)) - 1; A++ ) { if ( TempUnit[A].LNDType == ((byte)0) ) { UnitType = App.ObjectData.FindOrCreateUnitType(TempUnit[A].Code, clsUnitType.enumType.Feature, -1); } else if ( TempUnit[A].LNDType == ((byte)1) ) { UnitType = App.ObjectData.FindOrCreateUnitType(TempUnit[A].Code, clsUnitType.enumType.PlayerStructure, -1); } else if ( TempUnit[A].LNDType == ((byte)2) ) { UnitType = App.ObjectData.FindOrCreateUnitType(Convert.ToString(TempUnit[A].Code), clsUnitType.enumType.PlayerDroid, -1); } else { UnitType = null; } if ( UnitType != null ) { NewUnit = new clsUnit(); NewUnit.Type = UnitType; NewUnit.ID = TempUnit[A].ID; NewUnit.SavePriority = TempUnit[A].SavePriority; //NewUnit.Name = TempUnit(A).Name if ( TempUnit[A].Player >= Constants.PlayerCountMax ) { NewUnit.UnitGroup = ScavengerUnitGroup; } else { NewUnit.UnitGroup = UnitGroups[TempUnit[A].Player]; } NewUnit.Pos.Horizontal.X = Convert.ToInt32(TempUnit[A].X); //NewUnit.Pos.Altitude = TempUnit(A).Y NewUnit.Pos.Horizontal.Y = Convert.ToInt32(TempUnit[A].Z); NewUnit.Rotation = Math.Min(Convert.ToInt32(TempUnit[A].Rotation), 359); if ( TempUnit[A].ID == 0U ) { TempUnit[A].ID = AvailableID; App.ZeroIDWarning(NewUnit, TempUnit[A].ID, ReturnResult); } UnitAdd.ID = TempUnit[A].ID; UnitAdd.NewUnit = NewUnit; UnitAdd.Perform(); App.ErrorIDChange(TempUnit[A].ID, NewUnit, "Read_FMEv5+"); if ( AvailableID == TempUnit[A].ID ) { AvailableID = NewUnit.ID + 1U; } } else { WarningCount++; } } if ( WarningCount > 0 ) { ReturnResult.WarningAdd(WarningCount + " types of units were invalid. That many units were ignored."); } UInt32 NewGatewayCount = 0; sXY_int NewGateStart = new sXY_int(); sXY_int NewGateFinish = new sXY_int(); NewGatewayCount = File.ReadUInt32(); WarningCount = 0; for ( A = 0; A <= (Convert.ToInt32(NewGatewayCount)) - 1; A++ ) { NewGateStart.X = File.ReadUInt16(); NewGateStart.Y = File.ReadUInt16(); NewGateFinish.X = File.ReadUInt16(); NewGateFinish.Y = File.ReadUInt16(); if ( GatewayCreate(NewGateStart, NewGateFinish) == null ) { WarningCount++; } } if ( WarningCount > 0 ) { ReturnResult.WarningAdd(WarningCount + " gateways were invalid."); } if ( Tileset != null ) { for ( A = 0; A <= Tileset.TileCount - 1; A++ ) { byteTemp = File.ReadByte(); Tile_TypeNum[A] = byteTemp; } } //scroll limits ResultInfo.ScrollMin.X = File.ReadInt32(); ResultInfo.ScrollMin.Y = File.ReadInt32(); ResultInfo.ScrollMax.X = File.ReadUInt32(); ResultInfo.ScrollMax.Y = File.ReadUInt32(); //other compile info string strTemp = null; ResultInfo.CompileName = IOUtil.ReadOldText(File); byteTemp = File.ReadByte(); if ( byteTemp == ((byte)0) ) { //no compile type } else if ( byteTemp == ((byte)1) ) { //compile multi } else if ( byteTemp == ((byte)2) ) { //compile campaign } else { //error } ResultInfo.CompileMultiPlayers = IOUtil.ReadOldText(File); byteTemp = File.ReadByte(); if ( byteTemp == ((byte)0) ) { ResultInfo.CompileMultiXPlayers = false; } else if ( byteTemp == ((byte)1) ) { ResultInfo.CompileMultiXPlayers = true; } else { ReturnResult.WarningAdd("Compile player format out of range."); } ResultInfo.CompileMultiAuthor = IOUtil.ReadOldText(File); ResultInfo.CompileMultiLicense = IOUtil.ReadOldText(File); strTemp = IOUtil.ReadOldText(File); //game time ResultInfo.CampaignGameType = File.ReadInt32(); if ( ResultInfo.CampaignGameType < -1 | ResultInfo.CampaignGameType >= Constants.GameTypeCount ) { ReturnResult.WarningAdd("Compile campaign type out of range."); ResultInfo.CampaignGameType = -1; } if ( File.PeekChar() >= 0 ) { ReturnResult.WarningAdd("There were unread bytes at the end of the file."); } } else { ReturnResult.ProblemAdd("File version number not recognised."); } InterfaceOptions = ResultInfo; } catch ( Exception ex ) { ReturnResult.ProblemAdd("Read error: " + ex.Message); } return ReturnResult; }
public void MapInsert(clsMap MapToInsert, sXY_int Offset, sXY_int Area, bool InsertHeights, bool InsertTextures, bool InsertUnits, bool DeleteUnits, bool InsertGateways, bool DeleteGateways) { sXY_int Finish = new sXY_int(); int X = 0; int Y = 0; sXY_int SectorStart = new sXY_int(); sXY_int SectorFinish = new sXY_int(); sXY_int AreaAdjusted = new sXY_int(); sXY_int SectorNum = new sXY_int(); Finish.X = Math.Min(Offset.X + Math.Min(Area.X, MapToInsert.Terrain.TileSize.X), Terrain.TileSize.X); Finish.Y = Math.Min(Offset.Y + Math.Min(Area.Y, MapToInsert.Terrain.TileSize.Y), Terrain.TileSize.Y); AreaAdjusted.X = Finish.X - Offset.X; AreaAdjusted.Y = Finish.Y - Offset.Y; GetTileSectorRange(new sXY_int(Offset.X - 1, Offset.Y - 1), Finish, ref SectorStart, ref SectorFinish); for ( Y = SectorStart.Y; Y <= SectorFinish.Y; Y++ ) { SectorNum.Y = Y; for ( X = SectorStart.X; X <= SectorFinish.X; X++ ) { SectorNum.X = X; SectorGraphicsChanges.Changed(SectorNum); SectorUnitHeightsChanges.Changed(SectorNum); SectorTerrainUndoChanges.Changed(SectorNum); } } if ( InsertHeights ) { for ( Y = 0; Y <= AreaAdjusted.Y; Y++ ) { for ( X = 0; X <= AreaAdjusted.X; X++ ) { Terrain.Vertices[Offset.X + X, Offset.Y + Y].Height = MapToInsert.Terrain.Vertices[X, Y].Height; } } for ( Y = 0; Y <= AreaAdjusted.Y - 1; Y++ ) { for ( X = 0; X <= AreaAdjusted.X - 1; X++ ) { Terrain.Tiles[Offset.X + X, Offset.Y + Y].Tri = MapToInsert.Terrain.Tiles[X, Y].Tri; } } } if ( InsertTextures ) { for ( Y = 0; Y <= AreaAdjusted.Y; Y++ ) { for ( X = 0; X <= AreaAdjusted.X; X++ ) { Terrain.Vertices[Offset.X + X, Offset.Y + Y].Terrain = MapToInsert.Terrain.Vertices[X, Y].Terrain; } } bool TriDirection = default(bool); for ( Y = 0; Y <= AreaAdjusted.Y - 1; Y++ ) { for ( X = 0; X <= AreaAdjusted.X - 1; X++ ) { TriDirection = Terrain.Tiles[Offset.X + X, Offset.Y + Y].Tri; Terrain.Tiles[Offset.X + X, Offset.Y + Y].Copy(MapToInsert.Terrain.Tiles[X, Y]); Terrain.Tiles[Offset.X + X, Offset.Y + Y].Tri = TriDirection; } } for ( Y = 0; Y <= AreaAdjusted.Y; Y++ ) { for ( X = 0; X <= AreaAdjusted.X - 1; X++ ) { Terrain.SideH[Offset.X + X, Offset.Y + Y].Road = MapToInsert.Terrain.SideH[X, Y].Road; } } for ( Y = 0; Y <= AreaAdjusted.Y - 1; Y++ ) { for ( X = 0; X <= AreaAdjusted.X; X++ ) { Terrain.SideV[Offset.X + X, Offset.Y + Y].Road = MapToInsert.Terrain.SideV[X, Y].Road; } } } sXY_int LastTile = new sXY_int(); LastTile = Finish; LastTile.X--; LastTile.Y--; if ( DeleteGateways ) { int A = 0; A = 0; while ( A < Gateways.Count ) { if ( Gateways[A].PosA.IsInRange(Offset, LastTile) || Gateways[A].PosB.IsInRange(Offset, LastTile) ) { GatewayRemoveStoreChange(A); } else { A++; } } } if ( InsertGateways ) { sXY_int GateStart = new sXY_int(); sXY_int GateFinish = new sXY_int(); clsGateway Gateway = default(clsGateway); foreach ( clsGateway tempLoopVar_Gateway in MapToInsert.Gateways ) { Gateway = tempLoopVar_Gateway; GateStart.X = Offset.X + Gateway.PosA.X; GateStart.Y = Offset.Y + Gateway.PosA.Y; GateFinish.X = Offset.X + Gateway.PosB.X; GateFinish.Y = Offset.Y + Gateway.PosB.Y; if ( GateStart.IsInRange(Offset, LastTile) || GateFinish.IsInRange(Offset, LastTile) ) { GatewayCreateStoreChange(GateStart, GateFinish); } } } if ( DeleteUnits ) { SimpleList<clsUnit> UnitsToDelete = new SimpleList<clsUnit>(); int UnitToDeleteCount = 0; clsUnit Unit = default(clsUnit); for ( Y = SectorStart.Y; Y <= SectorFinish.Y; Y++ ) { for ( X = SectorStart.X; X <= SectorFinish.X; X++ ) { clsUnitSectorConnection Connection = default(clsUnitSectorConnection); foreach ( clsUnitSectorConnection tempLoopVar_Connection in Sectors[X, Y].Units ) { Connection = tempLoopVar_Connection; Unit = Connection.Unit; if ( App.PosIsWithinTileArea(Unit.Pos.Horizontal, Offset, Finish) ) { UnitsToDelete.Add(Unit); } } } } foreach ( clsUnit tempLoopVar_Unit in UnitsToDelete ) { Unit = tempLoopVar_Unit; if ( Unit.MapLink.IsConnected ) //units may be in the list multiple times and already be deleted { UnitRemoveStoreChange(Unit.MapLink.ArrayPosition); } } } if ( InsertUnits ) { sXY_int PosDif = new sXY_int(); clsUnit NewUnit = default(clsUnit); clsUnit Unit = default(clsUnit); sXY_int ZeroPos = new sXY_int(0, 0); clsUnitAdd UnitAdd = new clsUnitAdd(); UnitAdd.Map = this; UnitAdd.StoreChange = true; PosDif.X = Offset.X * App.TerrainGridSpacing; PosDif.Y = Offset.Y * App.TerrainGridSpacing; foreach ( clsUnit tempLoopVar_Unit in MapToInsert.Units ) { Unit = tempLoopVar_Unit; if ( App.PosIsWithinTileArea(Unit.Pos.Horizontal, ZeroPos, AreaAdjusted) ) { NewUnit = new clsUnit(Unit, this); NewUnit.Pos.Horizontal.X += PosDif.X; NewUnit.Pos.Horizontal.Y += PosDif.Y; UnitAdd.NewUnit = NewUnit; UnitAdd.Label = Unit.Label; UnitAdd.Perform(); } } } SectorsUpdateGraphics(); SectorsUpdateUnitHeights(); MinimapMakeLater(); }
public static string ToState(this clsUnit unit) { return(unit.Status == 0 || unit.Status == 100 ? UnitCommands.OFF.ToString() : UnitCommands.ON.ToString()); }