private void btnDelete_Click(object sender, EventArgs e) { if (MessageBox.Show("Do you want to delete Fee Temp . Temp No : [" + txtTempNo.Text + "]", "", System.Windows.Forms.MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.No) { return; } ArrayList arQuery = new ArrayList(); clsConnection clsCon = new clsConnection(); try { string sqlQuery = ""; //Delete Database sqlQuery = "Delete tblFee_Tmp Where FeeMgtID = " + double.Parse(txtTempNo.Tag.ToString()) + ""; arQuery.Add(sqlQuery); // Insert Information To Log File sqlQuery = "Insert Into GTRSystem.dbo.tblUser_Trans_Log (LUserId, formName, tranStatement, tranType)" + " Values (" + clsMain.intUserId + ", '" + this.Name.ToString() + "','" + sqlQuery.Replace("'", "|") + "','Delete')"; arQuery.Add(sqlQuery); //Transaction with database clsCon.GTRSaveDataWithSQLCommand(arQuery); MessageBox.Show("Data Delete Succefully"); prcClearData(); gridList.DataSource = null; } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { arQuery = null; clsCon = null; } }
private void prcLoadSaveData() { clsConnection clscon = new clsConnection(); dsList = new System.Data.DataSet(); try { string sqlquary = "Exec rptUnclaimed " + Common.Classes.clsMain.intComId + ", '','',0,0"; clscon.GTRFillDatasetWithSQLCommand(ref dsList, sqlquary); dsList.Tables[1].TableName = "Employee"; dsList.Tables[2].TableName = "AllowType"; dsList.Tables[3].TableName = "Grid"; gridEmployee.DataSource = dsList.Tables["Employee"]; gridDetails.DataSource = dsList.Tables["Grid"]; } catch (Exception ex) { throw (ex); } }
private void prcLoadList() { clsConnection clscon = new clsConnection(); dsList = new System.Data.DataSet(); try { string sqlquary = "Exec prcrptDaily " + Common.Classes.clsMain.intComId; clscon.GTRFillDatasetWithSQLCommand(ref dsList, sqlquary); dsList.Tables[0].TableName = "Section"; dsList.Tables[1].TableName = "Type"; dsList.Tables[2].TableName = "ShiftTime"; dsList.Tables[3].TableName = "Employee"; dsList.Tables[4].TableName = "Band"; gridSection.DataSource = null; gridSection.DataSource = dsList.Tables["Section"]; gridType.DataSource = null; gridType.DataSource = dsList.Tables["Type"]; gridShiftTime.DataSource = null; gridShiftTime.DataSource = dsList.Tables["ShiftTime"]; gridEmployeeID.DataSource = null; gridEmployeeID.DataSource = dsList.Tables["Employee"]; gridBand.DataSource = null; gridBand.DataSource = dsList.Tables["Band"]; dtDateFrom.Value = DateTime.Now; } catch (Exception ex) { throw (ex); } }
private void prcLoadList() { clsConnection clscon = new clsConnection(); dsList = new System.Data.DataSet(); try { string sqlquary = "Exec prcrptLeave " + Common.Classes.clsMain.intComId; clscon.GTRFillDatasetWithSQLCommand(ref dsList, sqlquary); dsList.Tables[0].TableName = "Criteria"; dsList.Tables[1].TableName = "Section"; dsList.Tables[2].TableName = "Employee"; dsList.Tables[3].TableName = "OpenDate"; dsList.Tables[4].TableName = "tblActive"; dsList.Tables[5].TableName = "tblEmpType"; gridCriteria.DataSource = dsList.Tables["Criteria"]; gridSec.DataSource = dsList.Tables["Section"]; gridEmp.DataSource = dsList.Tables["Employee"]; gridActive.DataSource = dsList.Tables["tblActive"]; gridEmpType.DataSource = dsList.Tables["tblEmpType"]; //gridSec.DataSource = dsList.Tables["IncType"]; DateTime firstDay = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1); dtDateFrom.Value = firstDay; DateTime lastDay = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1); lastDay = lastDay.AddMonths(1); lastDay = lastDay.AddDays(-(lastDay.Day)); dtDateTo.Value = lastDay; } catch (Exception ex) { throw (ex); } }
private void getRepairId() { try { using (clsConnection oConn = new clsConnection()) { NpgsqlCommand ocmd = new NpgsqlCommand(); string strSql = @"select * from tbm_carrepair where dlt=false"; DataTable dtData = oConn.GetData(strSql); //dgData.DataSource = dtData; if (dtData.Rows.Count == 0) { int bookingId = 1; strRepairid = clsGlobal.pstrservercode + "0" + bookingId++; } else { foreach (DataRow row in dtData.Rows) { int BookingId = Convert.ToInt32(row["repairid"].ToString().Substring(3, 2)); int IncBookingId = BookingId++; string strBookingId = Convert.ToString(BookingId++); string finalid = clsGlobal.pstrservercode + "0" + strBookingId; strRepairid = finalid; } } } } catch (NpgsqlException ex) { } catch (Exception ex) { } finally { } }
public void prcLoadList() { clsConnection clsCon = new clsConnection(); dsList = new System.Data.DataSet(); try { string SqlQuery = "Exec prcGetEmpFingerRegister 0,'" + Common.Classes.clsMain.intComId + "',0"; clsCon.GTRFillDatasetWithSQLCommand(ref dsList, SqlQuery); dsList.Tables[0].TableName = "tblFinger"; gridList.DataSource = null; gridList.DataSource = dsList.Tables["tblFinger"]; } catch (Exception ex) { throw (ex); } finally { clsCon = null; } }
public void prcLoadList(string strYear) { clsConnection clsCon = new clsConnection(); dsList = new System.Data.DataSet(); try { string SqlQuery = "Exec prcGetMonth " + strYear; clsCon.GTRFillDatasetWithSQLCommand(ref dsList, SqlQuery); dsList.Tables[0].TableName = "Year"; dsList.Tables[1].TableName = "Month"; gridList.DataSource = null; gridList.DataSource = dsList.Tables["Month"]; } catch (Exception ex) { throw (ex); } finally { clsCon = null; } }
public void prcLoadList() { clsConnection clsCon = new clsConnection(); dsList = new System.Data.DataSet(); try { string SqlQuery = "Exec prcGetVariableDetails '" + this.Tag.ToString() + "'"; clsCon.GTRFillDatasetWithSQLCommand(ref dsList, SqlQuery); dsList.Tables[0].TableName = "Varible"; gridList.DataSource = null; gridList.DataSource = dsList.Tables["Varible"]; } catch (Exception ex) { throw (ex); } finally { clsCon = null; } }
public void GTRLoadCombo(ref Infragistics.Win.UltraWinGrid.UltraCombo cbo, string sqlQuery, string DisplayMember, string ValueMember) { clsConnection clsCon = new clsConnection(); try { System.Data.DataSet ds = new System.Data.DataSet(); clsCon.GTRFillDatasetWithSQLCommand(ref ds, sqlQuery); cbo.DataSource = ds.Tables[0]; cbo.DisplayMember = DisplayMember; cbo.ValueMember = ValueMember; } catch (Exception ex) { throw (ex); } finally { clsCon = null; } }
private void btnCalculate_Click(object sender, EventArgs e) { ArrayList arQuery = new ArrayList(); clsConnection clsCon = new clsConnection(); Int32 rowCount; try { for (rowCount = 0; rowCount < dsList.Tables["Grid"].Rows.Count; rowCount++) { gridDetails.Rows[rowCount].Cells[8].Value = txtAmount.Text.ToString(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { clsCon = null; } }
private void prcLoadList() { clsConnection clscon = new clsConnection(); string sqlQuery; dsList = new System.Data.DataSet(); try { sqlQuery = "Exec prcGetDatabaseBK "; clscon.GTRFillDatasetWithSQLCommand(ref dsList, sqlQuery); dsList.Tables[0].TableName = "DbName"; gridDataBKUp.DataSource = null; gridDataBKUp.DataSource = dsList.Tables["DbName"]; } catch (Exception ex) { throw(ex); } finally { clscon = null; } }
public void prcLoadList() { clsConnection clsCon = new clsConnection(); dsList = new System.Data.DataSet(); try { string SqlQuery = "Exec prcGetBusStop " + Common.Classes.clsMain.intComId + ",0,'" + this.Tag.ToString() + "'"; clsCon.GTRFillDatasetWithSQLCommand(ref dsList, SqlQuery); dsList.Tables[0].TableName = "BusStop"; gridList.DataSource = null; gridList.DataSource = dsList.Tables["BusStop"]; } catch (Exception ex) { throw (ex); } finally { clsCon = null; } }
private void prcLoadLoan() { clsConnection clsCon = new clsConnection(); dsList = new System.Data.DataSet(); try { string sqlQuery = "Exec prcProcessLoanUpdate " + Common.Classes.clsMain.intComId + ",'" + cboEmpID.Value.ToString() + "','" + clsProc.GTRDate(dtDateFrom.Value.ToString()) + "'"; clsCon.GTRFillDatasetWithSQLCommand(ref dsList, sqlQuery); dsList.Tables[0].TableName = "tblgrid"; gridData.DataSource = null; gridData.DataSource = dsList.Tables["tblgrid"]; } catch (Exception ex) { throw ex; } finally { clsCon = null; } }
private void SnotelDBLoader_FormClosing(object sender, FormClosingEventArgs e) { //When the dialog box is closed without saving it sends a dialogresult.cancel //Input: m_NewConnection, m_Saving, and User Inputs -> Used to decide whether to store the connection or not. //Output: FinalConnsettings, Me.dialogresult ->Stores Successful connection settings to CurrConnSettings, and sends a dialogresult.ok //if( saving { save the settings if (m_Saving) { //return an OK dialog result this.DialogResult = System.Windows.Forms.DialogResult.OK; } else { m_ConnSettings = new clsConnection(); this.DialogResult = System.Windows.Forms.DialogResult.Cancel; } writeXML(1, 1); Process p = new Process(); //p.StartInfo.FileName = (g_EXE_Dir + "\\UpdateSnotel.exe"); p.Start(); }
/// <summary> /// Eliminamos a una persona con el verbo delete /// </summary> /// <param name="id"></param> /// <returns></returns> public async Task <int> eliminarPersonaDALAsync(int id) { clsConnection mConexion = new clsConnection(); int mResultado = 0; HttpClient client = new HttpClient(); HttpResponseMessage respuesta; Uri mUri = new Uri(mConexion.uriBase + "/" + id); try { respuesta = await client.DeleteAsync(mUri); client.Dispose(); if (respuesta.IsSuccessStatusCode) { mResultado = 1; } } catch (Exception e) { throw e; } return(mResultado); }
private void prcLoadList() { clsConnection clsCon = new clsConnection(); dsList = new System.Data.DataSet(); try { string sqlQuery = "Exec [prcGetEmployeeList] " + Common.Classes.clsMain.intComId + ", 0"; clsCon.GTRFillDatasetWithSQLCommand(ref dsList, sqlQuery); dsList.Tables[0].TableName = "tblgrid"; gridList.DataSource = null; gridList.DataSource = dsList.Tables["tblGrid"]; } catch (Exception ex) { throw ex; } finally { clsCon = null; } }
public void prcLoadList() { clsConnection clsCon = new clsConnection(); dsList = new System.Data.DataSet(); try { string SqlQuery = "Exec prcGetCorporateBusiness 0,'Corporate'"; clsCon.GTRFillDatasetWithSQLCommand(ref dsList, SqlQuery); dsList.Tables[0].TableName = "Corporate"; gridList.DataSource = null; gridList.DataSource = dsList.Tables["Corporate"]; } catch (Exception ex) { throw(ex); } finally { clsCon = null; } }
public void loadData() { try { using (clsConnection oConn = new clsConnection()) { NpgsqlCommand ocmd = new NpgsqlCommand(); frmMain.setLoadDialog(true, "Loading data..."); string strSql = @"select a.carid, a.platnumber,a.imagename,a.typeid,a.filepath_car,a.passengercapacity,a.price,a.description, a.statusavailable, b.typeid,b.carcategoryid as categoryid, b.carbrandid,b.typename, c.carcategoryid as categoryid,c.carcategoryname as categoryname, d.carbrandid as brandids,d.brandname from tbm_car a left join tbm_cartype b on b.typeid = a.typeid and b.dlt='0' left join tbm_carcategory c on c.carcategoryid = b.carcategoryid and c.dlt='0' left join tbm_carbrand d on d.carbrandid = b.carbrandid and d.dlt='0' where a.dlt=false order by a.statusavailable;"; DataTable dtData = oConn.GetData(strSql); dgData.DataSource = dtData; foreach (DataRow row in dtData.Rows) { } gridViewData.Columns[1].ColumnEdit = ricmbCarType; } } catch (NpgsqlException ex) { } catch (Exception ex) { } finally { frmMain.setLoadDialog(false, ""); } }
private void prcLoadList() { dsList = new DataSet(); clsConnection clsCon = new clsConnection(); string sqlQuery = ""; try { sqlQuery = "Exec prcGetUploadExcel " + clsMain.intComId; clsCon.GTRFillDatasetWithSQLCommand(ref dsList, sqlQuery); dsList.Tables[0].TableName = "Grid"; gridList.DataSource = null; gridList.DataSource = dsList.Tables["Grid"]; } catch (Exception ex) { throw(ex); } finally { clsCon = null; } }
private void prcRawData() { clsConnection clsCon = new clsConnection(); string sqlQuery = ""; dsDetails = new DataSet(); try { sqlQuery = "Exec prcGetIpAddressGTR 1," + Common.Classes.clsMain.intComId + ""; clsCon.GTRFillDatasetWithSQLCommand(ref dsDetails, sqlQuery); dsDetails.Tables[0].TableName = "Raw"; gridInfo.DataSource = null; gridInfo.DataSource = dsDetails.Tables["Raw"]; } catch (Exception ex) { throw (ex); } finally { clsCon = null; } }
public void prcLoadList() { clsConnection clsCon = new clsConnection(); dsList = new System.Data.DataSet(); try { string sqlQuery = "Exec prcGetProcessLock " + Common.Classes.clsMain.intComId + ",0"; clsCon.GTRFillDatasetWithSQLCommand(ref dsList, sqlQuery); dsList.Tables[0].TableName = "tblGrid"; dsList.Tables[1].TableName = "tblType"; gridList.DataSource = null; gridList.DataSource = dsList.Tables["tblGrid"]; } catch (Exception ex) { throw (ex); } finally { clsCon = null; } }
private void btnLoad_Click(object sender, EventArgs e) { clsConnection clsCon = new clsConnection(); string sqlQuery = ""; dsList = new DataSet(); string Band = ""; string SectId = "0", EmpId = "0", ProssType = ""; ProssType = gridProssType.ActiveRow.Cells["ProssType"].Value.ToString(); SectId = gridSec.ActiveRow.Cells["SectId"].Value.ToString(); Band = gridBand.ActiveRow.Cells["varName"].Value.ToString(); try { sqlQuery = "Exec [rptFestAdvanceSheet] " + Common.Classes.clsMain.intComId + ", '" + gridProssType.ActiveRow.Cells[0].Value.ToString() + "','1', '1','" + gridSec.ActiveRow.Cells[0].Value.ToString() + "','1','" + Band + "','1',7"; clsCon.GTRFillDatasetWithSQLCommand(ref dsList, sqlQuery); dsList.Tables[0].TableName = "tblGrid"; gridDetails.DataSource = null; gridDetails.DataSource = dsList.Tables["tblGrid"]; } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { clsCon = null; } }
private void loadBookingId() { using (clsConnection oConn = new clsConnection()) { string strSql = @"select * from tbm_booking"; DataTable dtData = oConn.GetData(strSql); if (dtData.Rows.Count == 0) { int bookingId = 1; txtBookingId.Text = clsGlobal.pstrservercode + "0" + bookingId++; } else { foreach (DataRow row in dtData.Rows) { int BookingId = Convert.ToInt32(row["bookingid"].ToString().Substring(3, 2)); int IncBookingId = BookingId++; string strBookingId = Convert.ToString(BookingId++); string finalid = clsGlobal.pstrservercode + "0" + strBookingId; txtBookingId.Text = finalid; } } } }
private void btnDelete_Click(object sender, EventArgs e) { if (MessageBox.Show("Do you want to delete Process information of [" + btnDelete.Tag + "]", "", System.Windows.Forms.MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.No) { return; } clsConnection clsCon = new clsConnection(); ArrayList arQuery = new ArrayList(); try { string SQLQuery = "Delete From tblDN_xls_Main where EntryNo='" + btnDelete.Tag + "'"; arQuery.Add(SQLQuery); // Insert Information To Log File SQLQuery = "Insert Into Gtrsystem.dbo.tblUser_Trans_Log (LUserId, formName, tranStatement, tranType)" + " Values (" + Common.Classes.clsMain.intUserId + ", '" + this.Name.ToString() + "','" + SQLQuery.Replace("'", "|") + "','Delete')"; arQuery.Add(SQLQuery); clsCon.GTRSaveDataWithSQLCommand(arQuery); MessageBox.Show("Data Delete successfully."); // btnProcess.Enabled = false; prcLoadList(); btnDelete.Visible = false; btnDelete.Enabled = false; } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { clsCon = null; } }
public void prcLoadListIndividual(string str) { clsConnection clsCon = new clsConnection(); dsList = new System.Data.DataSet(); try { string sqlQuery = " Select A.lvId, A.empId, B.empCode, B.empName, A.lvType, CONVERT(varchar,A.dtFrom,106) as dtFrom, CONVERT(Varchar, A.dtTo,106)As dtTo, A.totalDay, A.lvApp, A.Remark From tblLeave_Avail A Inner Join tblEmp_Info B On B.empID = A.EmpId where A.empid = '" + txtEmpID.Text.ToString() + "' order by lvId desc"; clsCon.GTRFillDatasetWithSQLCommand(ref dsList, sqlQuery); dsList.Tables[0].TableName = "Leave"; gridList.DataSource = null; gridList.DataSource = dsList.Tables["Leave"]; } catch (Exception ex) { throw (ex); } finally { clsCon = null; } }
private void prcDisplayDetails(string param) { try { string sqlQuery = "Exec prcGetHaySystem " + Common.Classes.clsMain.intComId + ", " + Int32.Parse(param); dsDetails = new System.Data.DataSet(); clsConnection clsCon = new clsConnection(); clsCon.GTRFillDatasetWithSQLCommand(ref dsDetails, sqlQuery); dsDetails.Tables[0].TableName = "Details"; DataRow dr; if (dsDetails.Tables["Details"].Rows.Count > 0) { dr = dsDetails.Tables["Details"].Rows[0]; this.txtCode.Value = dr["HCode"].ToString(); this.txtCode.Tag = dr["HId"].ToString(); this.txtName.Text = dr["HName"].ToString(); this.txtNameShort.Text = dr["HNameShort"].ToString(); this.cboUnder.Value = dr["ParentId"].ToString(); if (dr["HType"].ToString() == "L") { optType.CheckedIndex = 1; } this.btnSave.Text = "&Update"; this.btnDelete.Enabled = true; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public void loadData() { try { using (clsConnection oConn = new clsConnection()) { NpgsqlCommand ocmd = new NpgsqlCommand(); frmMain.setLoadDialog(true, "Loading data..."); string strSql = @"select a.repairid,a.carid,b.platnumber from tbm_carrepair a inner join tbm_car b on b.carid=a.carid and b.dlt='0'"; DataTable dtData = oConn.GetData(strSql); dgData.DataSource = dtData; } } catch (NpgsqlException ex) { } catch (Exception ex) { } finally { frmMain.setLoadDialog(false, ""); } }
private void btnLoad_Click(object sender, EventArgs e) { clsConnection clsCon = new clsConnection(); string sqlQuery = ""; dsList = new DataSet(); gridEmp.Enabled = true; //Collecting Parameter Value string ShiftCode = gridShift.ActiveRow.Cells["ShiftId"].Value.ToString(); try { string SqlQuery = "Exec prcGetShiftInput " + Common.Classes.clsMain.intComId + ",1,'" + ShiftCode + "'"; clsCon.GTRFillDatasetWithSQLCommand(ref dsList, SqlQuery); dsList.Tables[0].TableName = "tblEmployee"; gridEmp.DataSource = null; gridEmp.DataSource = dsList.Tables["tblEmployee"]; checkBox2.Checked = false; } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { clsCon = null; } }
private void gridList_AfterCellUpdate(object sender, CellEventArgs e) { if (gridList.ActiveRow.IsFilterRow != true) { DataSet dsChange = new DataSet(); clsConnection clscon = new clsConnection(); string sqlQuery = ""; try { sqlQuery = "Exec prcProcessManualAtt " + Common.Classes.clsMain.intComId + ",'" + gridList.ActiveRow.Cells["empid"].Value + "','" + clsProc.GTRDate(gridList.ActiveRow.Cells["dtPunchDate"].Value.ToString()) + "', " + gridList.ActiveRow.Cells["ShiftId"].Value + ",'" + gridList.ActiveRow.Cells["TimeIn"].Value.ToString() + "','" + gridList.ActiveRow.Cells["TimeOut"].Value.ToString() + "' "; clscon.GTRFillDatasetWithSQLCommand(ref dsChange, sqlQuery); dsChange.Tables[0].TableName = "Change"; DataRow dr = dsChange.Tables["Change"].Rows[0]; if (dsChange.Tables["Change"].Rows.Count > 0) { gridList.ActiveRow.Cells["OTHour"].Value = dr["OtHour"]; } } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
public void prcDisplayDetails(string strParam) { clsConnection clsCon = new clsConnection(); dsDetail = new System.Data.DataSet(); try { string SqlQuery = "Exec prcGetSection '" + Common.Classes.clsMain.intComId + "'," + Int32.Parse(strParam) + ""; clsCon.GTRFillDatasetWithSQLCommand(ref dsDetail, SqlQuery); dsDetail.Tables[0].TableName = "details"; DataRow dr; if (dsDetail.Tables["details"].Rows.Count > 0) { dr = dsDetail.Tables["details"].Rows[0]; txtId.Text = dr["SectId"].ToString(); txtName.Text = dr["SectName"].ToString(); txtNameB.Text = dr["SectNameB"].ToString(); txtSlNo.Text = dr["SLNO"].ToString(); //cboDept.Text = dr["DeptId"].ToString(); // txtNameB.Text = dr["DesigNameB"].ToString(); btnSave.Text = "&Update"; btnDelete.Enabled = true; } } catch (Exception ex) { throw (ex); } finally { clsCon = null; } }
public clsResult GenerateLayout() { clsResult ReturnResult = new clsResult("Layout"); int X = 0; int Y = 0; int A = 0; int B = 0; int C = 0; int D = 0; int E = 0; int F = 0; int G = 0; int H = 0; TotalPlayerCount = TopLeftPlayerCount * SymmetryBlockCount; sXY_int SymmetrySize = new sXY_int(); SymmetrySize.X = (int)(TileSize.X * App.TerrainGridSpacing / SymmetryBlockCountXY.X); SymmetrySize.Y = (int)(TileSize.Y * App.TerrainGridSpacing / SymmetryBlockCountXY.Y); //create passage nodes int PassageRadius = (int)(128.0F * NodeScale); int MaxLikelyPassageNodeCount = 0; MaxLikelyPassageNodeCount = (int)(Math.Ceiling(Convert.ToDecimal(2.0D * TileSize.X * 128 * TileSize.Y * 128 / (Math.PI * PassageRadius * PassageRadius)))); PassageNodes = new clsPassageNode[SymmetryBlockCount, MaxLikelyPassageNodeCount]; int LoopCount = 0; int EdgeOffset = 0 * 128; bool PointIsValid; sXY_int EdgeSections = new sXY_int(); Position.XY_dbl EdgeSectionSize = default(Position.XY_dbl); sXY_int NewPointPos = new sXY_int(); if ( SymmetryBlockCountXY.X == 1 ) { EdgeSections.X = Convert.ToInt32( Conversion.Int((TileSize.X * App.TerrainGridSpacing - EdgeOffset * 2.0D) / (NodeScale * App.TerrainGridSpacing * 2.0F))); EdgeSectionSize.X = (TileSize.X * App.TerrainGridSpacing - EdgeOffset * 2.0D) / EdgeSections.X; EdgeSections.X--; } else { EdgeSections.X = (int) (Conversion.Int((TileSize.X * App.TerrainGridSpacing / SymmetryBlockCountXY.X - EdgeOffset) / (NodeScale * App.TerrainGridSpacing * 2.0F) - 0.5D)); EdgeSectionSize.X = Convert.ToDouble((TileSize.X * App.TerrainGridSpacing / SymmetryBlockCountXY.X - EdgeOffset) / (Convert.ToDouble( Conversion.Int((TileSize.X * App.TerrainGridSpacing / SymmetryBlockCountXY.X - EdgeOffset) / (NodeScale * App.TerrainGridSpacing * 2.0F) - 0.5D)) + 0.5D)); } if ( SymmetryBlockCountXY.Y == 1 ) { EdgeSections.Y = Convert.ToInt32( Conversion.Int((TileSize.Y * App.TerrainGridSpacing - EdgeOffset * 2.0D) / (NodeScale * App.TerrainGridSpacing * 2.0F))); EdgeSectionSize.Y = (TileSize.Y * App.TerrainGridSpacing - EdgeOffset * 2.0D) / EdgeSections.Y; EdgeSections.Y--; } else { EdgeSections.Y = Convert.ToInt32( Conversion.Int((TileSize.Y * App.TerrainGridSpacing / SymmetryBlockCountXY.Y - EdgeOffset) / (NodeScale * App.TerrainGridSpacing * 2.0F) - 0.5D)); EdgeSectionSize.Y = Convert.ToDouble((TileSize.Y * App.TerrainGridSpacing / SymmetryBlockCountXY.Y - EdgeOffset) / (Convert.ToDouble( Conversion.Int((TileSize.Y * App.TerrainGridSpacing / SymmetryBlockCountXY.Y - EdgeOffset) / (NodeScale * App.TerrainGridSpacing * 2.0F) - 0.5D)) + 0.5D)); } PassageNodeCount = 0; for ( Y = 0; Y <= EdgeSections.Y; Y++ ) { if ( !MakePassageNodes(new sXY_int(EdgeOffset, EdgeOffset + (int)(Y * EdgeSectionSize.Y)), true) ) { ReturnResult.ProblemAdd("Error: Bad border node."); return ReturnResult; } if ( SymmetryBlockCountXY.X == 1 ) { if ( !MakePassageNodes(new sXY_int(TileSize.X * App.TerrainGridSpacing - EdgeOffset, EdgeOffset + (int)(Y * EdgeSectionSize.Y)), true) ) { ReturnResult.ProblemAdd("Error: Bad border node."); return ReturnResult; } } } for ( X = 1; X <= EdgeSections.X; X++ ) { if ( !MakePassageNodes(new sXY_int(EdgeOffset + (int)(X * EdgeSectionSize.X), EdgeOffset), true) ) { ReturnResult.ProblemAdd("Error: Bad border node."); return ReturnResult; } if ( SymmetryBlockCountXY.Y == 1 ) { if ( !MakePassageNodes(new sXY_int(EdgeOffset + (int)(X * EdgeSectionSize.X), TileSize.Y * App.TerrainGridSpacing - EdgeOffset), true) ) { ReturnResult.ProblemAdd("Error: Bad border node."); return ReturnResult; } } } do { LoopCount = 0; do { PointIsValid = true; if ( SymmetryBlockCountXY.X == 1 ) { NewPointPos.X = (int)(EdgeOffset + Conversion.Int(VBMath.Rnd() * (SymmetrySize.X - EdgeOffset * 2 + 1))); } else { NewPointPos.X = EdgeOffset + (int)(Conversion.Int(VBMath.Rnd() * (SymmetrySize.X - EdgeOffset + 1))); } if ( SymmetryBlockCountXY.Y == 1 ) { NewPointPos.Y = EdgeOffset + (int)(Conversion.Int(VBMath.Rnd() * (SymmetrySize.Y - EdgeOffset * 2 + 1))); } else { NewPointPos.Y = EdgeOffset + Convert.ToInt32(Conversion.Int(VBMath.Rnd() * (SymmetrySize.Y - EdgeOffset + 1))); } for ( A = 0; A <= PassageNodeCount - 1; A++ ) { for ( B = 0; B <= SymmetryBlockCount - 1; B++ ) { if ( (PassageNodes[B, A].Pos - NewPointPos).ToDoubles().GetMagnitude() < PassageRadius * 2 ) { goto PointTooClose; } } } PointTooClose: if ( A == PassageNodeCount ) { if ( MakePassageNodes(NewPointPos, false) ) { break; } } LoopCount++; if ( LoopCount >= (int)(64.0F * TileSize.X * TileSize.Y / (NodeScale * NodeScale)) ) { goto PointMakingFinished; } } while ( true ); } while ( true ); PointMakingFinished: PassageNodes = (clsPassageNode[,]) Utils.CopyArray((Array)PassageNodes, new clsPassageNode[SymmetryBlockCount, PassageNodeCount]); //connect until all are connected without intersecting MathUtil.sIntersectPos IntersectPos = new MathUtil.sIntersectPos(); int MaxConDist2 = PassageRadius * 2 * 4; MaxConDist2 *= MaxConDist2; clsNearest NearestA = default(clsNearest); Nearests = new clsNearest[PassageNodeCount * 64]; clsPassageNode tmpPassageNodeA = default(clsPassageNode); clsPassageNode tmpPassageNodeB = default(clsPassageNode); clsTestNearestArgs NearestArgs = new clsTestNearestArgs(); int MinConDist = (int)(NodeScale * 1.25F * 128.0F); NearestArgs.MaxConDist2 = MaxConDist2; NearestArgs.MinConDist = MinConDist; for ( A = 0; A <= PassageNodeCount - 1; A++ ) { NearestArgs.PassageNodeA = PassageNodes[0, A]; for ( B = A; B <= PassageNodeCount - 1; B++ ) { for ( C = 0; C <= SymmetryBlockCount - 1; C++ ) { NearestArgs.PassageNodeB = PassageNodes[C, B]; if ( NearestArgs.PassageNodeA != NearestArgs.PassageNodeB ) { TestNearest(NearestArgs); } } } } clsNearest NearestB = default(clsNearest); bool Flag = default(bool); for ( G = 0; G <= NearestCount - 1; G++ ) { NearestA = Nearests[G]; for ( A = 0; A <= NearestA.NodeCount - 1; A++ ) { tmpPassageNodeA = NearestA.NodeA[A]; tmpPassageNodeB = NearestA.NodeB[A]; for ( H = 0; H <= NearestCount - 1; H++ ) { NearestB = Nearests[H]; if ( NearestB != NearestA ) { if ( NearestB.Dist2 < NearestA.Dist2 ) { Flag = true; } else if ( NearestB.Dist2 == NearestA.Dist2 ) { Flag = NearestA.Num > NearestB.Num; } else { Flag = false; } if ( Flag ) { for ( B = 0; B <= NearestB.NodeCount - 1; B++ ) { if ( !(tmpPassageNodeA == NearestB.NodeA[B] || tmpPassageNodeA == NearestB.NodeB[B] || tmpPassageNodeB == NearestB.NodeA[B] || tmpPassageNodeB == NearestB.NodeB[B]) ) { IntersectPos = MathUtil.GetLinesIntersectBetween(tmpPassageNodeA.Pos, tmpPassageNodeB.Pos, NearestB.NodeA[B].Pos, NearestB.NodeB[B].Pos); if ( IntersectPos.Exists ) { break; } } } if ( B < NearestB.NodeCount ) { NearestA.BlockedCount++; NearestB.BlockedNearests[NearestB.BlockedNearestCount] = NearestA; NearestB.BlockedNearestCount++; } } } } } } int ChangeCount = 0; Connections = new clsConnection[PassageNodeCount * 16]; do { //create valid connections ChangeCount = 0; G = 0; while ( G < NearestCount ) { NearestA = Nearests[G]; Flag = true; if ( NearestA.BlockedCount == 0 && Flag ) { F = ConnectionCount; for ( D = 0; D <= NearestA.NodeCount - 1; D++ ) { Connections[ConnectionCount] = new clsConnection(NearestA.NodeA[D], NearestA.NodeB[D]); ConnectionCount++; } for ( D = 0; D <= NearestA.NodeCount - 1; D++ ) { A = F + D; Connections[A].ReflectionCount = NearestA.NodeCount - 1; Connections[A].Reflections = new clsConnection[Connections[A].ReflectionCount]; B = 0; for ( E = 0; E <= NearestA.NodeCount - 1; E++ ) { if ( E != D ) { Connections[A].Reflections[B] = Connections[F + E]; B++; } } } for ( C = 0; C <= NearestA.BlockedNearestCount - 1; C++ ) { NearestA.BlockedNearests[C].Invalid = true; } NearestCount--; H = NearestA.Num; NearestA.Num = -1; if ( H != NearestCount ) { Nearests[H] = Nearests[NearestCount]; Nearests[H].Num = H; } ChangeCount++; } else { if ( !Flag ) { NearestA.Invalid = true; } G++; } } //remove blocked ones and their blocking effect G = 0; while ( G < NearestCount ) { NearestA = Nearests[G]; if ( NearestA.Invalid ) { NearestA.Num = -1; for ( D = 0; D <= NearestA.BlockedNearestCount - 1; D++ ) { NearestA.BlockedNearests[D].BlockedCount--; } NearestCount--; if ( G != NearestCount ) { Nearests[G] = Nearests[NearestCount]; Nearests[G].Num = G; } } else { G++; } } } while ( ChangeCount > 0 ); //put connections in order of angle for ( A = 0; A <= PassageNodeCount - 1; A++ ) { for ( B = 0; B <= SymmetryBlockCount - 1; B++ ) { PassageNodes[B, A].ReorderConnections(); PassageNodes[B, A].CalcIsNearBorder(); } } //get nodes in random order clsPassageNode[] PassageNodeListOrder = new clsPassageNode[PassageNodeCount]; int PassageNodeListOrderCount = 0; clsPassageNode[] PassageNodeOrder = new clsPassageNode[PassageNodeCount]; for ( A = 0; A <= PassageNodeCount - 1; A++ ) { PassageNodeListOrder[PassageNodeListOrderCount] = PassageNodes[0, A]; PassageNodeListOrderCount++; } B = 0; while ( PassageNodeListOrderCount > 0 ) { A = (int)(Conversion.Int(VBMath.Rnd() * PassageNodeListOrderCount)); PassageNodeOrder[B] = PassageNodeListOrder[A]; B++; PassageNodeListOrderCount--; PassageNodeListOrder[A] = PassageNodeListOrder[PassageNodeListOrderCount]; } //designate height levels LevelHeight = 255.0F / (LevelCount - 1); int BestNum = 0; double Dist = 0; clsPassageNodeHeightLevelArgs HeightsArgs = new clsPassageNodeHeightLevelArgs(); HeightsArgs.PassageNodesMinLevel.Nodes = new int[PassageNodeCount]; HeightsArgs.PassageNodesMaxLevel.Nodes = new int[PassageNodeCount]; HeightsArgs.MapLevelCount = new int[LevelCount]; sXY_int RotatedPos = new sXY_int(); for ( A = 0; A <= PassageNodeCount - 1; A++ ) { HeightsArgs.PassageNodesMinLevel.Nodes[A] = 0; HeightsArgs.PassageNodesMaxLevel.Nodes[A] = LevelCount - 1; } //create bases double[] BestDists = new double[BaseFlatArea]; clsPassageNode[] BestNodes = new clsPassageNode[BaseFlatArea]; int[] BestNodesReflectionNums = new int[BaseFlatArea]; int BestDistCount = 0; PlayerBases = new sPlayerBase[TotalPlayerCount]; for ( B = 0; B <= TopLeftPlayerCount - 1; B++ ) { BestDistCount = 0; for ( A = 0; A <= PassageNodeCount - 1; A++ ) { for ( E = 0; E <= SymmetryBlockCount - 1; E++ ) { tmpPassageNodeA = PassageNodes[E, A]; if ( !tmpPassageNodeA.IsOnBorder ) { Dist = (tmpPassageNodeA.Pos - PlayerBasePos[B]).ToDoubles().GetMagnitude(); for ( C = BestDistCount - 1; C >= 0; C-- ) { if ( Dist > BestDists[C] ) { break; } } C++; for ( D = Math.Min(BestDistCount - 1, BaseFlatArea - 2); D >= C; D-- ) { BestDists[D + 1] = BestDists[D]; BestNodes[D + 1] = BestNodes[D]; } if ( C < BaseFlatArea ) { BestDists[C] = Dist; BestNodes[C] = tmpPassageNodeA; BestDistCount = Math.Max(BestDistCount, C + 1); } } } } if ( BaseLevel < 0 ) { D = Convert.ToInt32(Conversion.Int(VBMath.Rnd() * LevelCount)); } else { D = BaseLevel; } HeightsArgs.MapLevelCount[D] += BestDistCount; for ( A = 0; A <= BestDistCount - 1; A++ ) { if ( BestNodes[A].MirrorNum == 0 ) { BestNodesReflectionNums[A] = -1; } else { for ( C = 0; C <= ((int)(SymmetryBlockCount / 2.0D)) - 1; C++ ) { if ( SymmetryBlocks[0].ReflectToNum[C] == BestNodes[A].MirrorNum ) { break; } } BestNodesReflectionNums[A] = C; } } for ( A = 0; A <= SymmetryBlockCount - 1; A++ ) { E = A * TopLeftPlayerCount + B; PlayerBases[E].NodeCount = BestDistCount; PlayerBases[E].Nodes = new clsPassageNode[PlayerBases[E].NodeCount]; for ( C = 0; C <= BestDistCount - 1; C++ ) { if ( BestNodesReflectionNums[C] < 0 ) { PlayerBases[E].Nodes[C] = PassageNodes[A, BestNodes[C].Num]; } else { PlayerBases[E].Nodes[C] = PassageNodes[SymmetryBlocks[A].ReflectToNum[BestNodesReflectionNums[C]], BestNodes[C].Num]; } PlayerBases[E].Nodes[C].PlayerBaseNum = E; PlayerBases[E].Nodes[C].Level = D; PassageNodesMinLevelSet(PlayerBases[E].Nodes[C], HeightsArgs.PassageNodesMinLevel, D, MaxLevelTransition); PassageNodesMaxLevelSet(PlayerBases[E].Nodes[C], HeightsArgs.PassageNodesMaxLevel, D, MaxLevelTransition); } //PlayerBases(E).CalcPos() RotatedPos = TileUtil.GetRotatedPos(SymmetryBlocks[A].Orientation, PlayerBasePos[B], new sXY_int(SymmetrySize.X - 1, SymmetrySize.Y - 1)); PlayerBases[E].Pos.X = SymmetryBlocks[A].XYNum.X * SymmetrySize.X + RotatedPos.X; PlayerBases[E].Pos.Y = SymmetryBlocks[A].XYNum.Y * SymmetrySize.Y + RotatedPos.Y; } } int WaterCount = 0; bool CanDoFlatsAroundWater = default(bool); int TotalWater = 0; int WaterSpawns = 0; for ( A = 0; A <= PassageNodeCount - 1; A++ ) { tmpPassageNodeA = PassageNodeOrder[A]; if ( tmpPassageNodeA.Level < 0 && !tmpPassageNodeA.IsOnBorder ) { WaterCount = 0; for ( B = 0; B <= tmpPassageNodeA.ConnectionCount - 1; B++ ) { tmpPassageNodeB = tmpPassageNodeA.Connections[B].GetOther(); if ( tmpPassageNodeB.IsWater ) { WaterCount++; } } CanDoFlatsAroundWater = true; for ( B = 0; B <= tmpPassageNodeA.ConnectionCount - 1; B++ ) { if ( HeightsArgs.PassageNodesMinLevel.Nodes[tmpPassageNodeA.Connections[B].GetOther().Num] > 0 ) { CanDoFlatsAroundWater = false; } } if ( CanDoFlatsAroundWater && ((WaterCount == 0 & WaterSpawns < WaterSpawnQuantity) || (WaterCount == 1 & TotalWaterQuantity - TotalWater > WaterSpawnQuantity - WaterSpawns)) && HeightsArgs.PassageNodesMinLevel.Nodes[tmpPassageNodeA.Num] == 0 & TotalWater < TotalWaterQuantity ) { if ( WaterCount == 0 ) { WaterSpawns++; } TotalWater++; C = tmpPassageNodeA.Num; for ( D = 0; D <= SymmetryBlockCount - 1; D++ ) { PassageNodes[D, C].IsWater = true; PassageNodes[D, C].Level = 0; } PassageNodesMinLevelSet(tmpPassageNodeA, HeightsArgs.PassageNodesMinLevel, 0, MaxLevelTransition); PassageNodesMaxLevelSet(tmpPassageNodeA, HeightsArgs.PassageNodesMaxLevel, 0, MaxLevelTransition); HeightsArgs.MapLevelCount[0]++; for ( B = 0; B <= tmpPassageNodeA.ConnectionCount - 1; B++ ) { tmpPassageNodeB = tmpPassageNodeA.Connections[B].GetOther(); PassageNodesMinLevelSet(tmpPassageNodeB, HeightsArgs.PassageNodesMinLevel, 0, MaxLevelTransition); PassageNodesMaxLevelSet(tmpPassageNodeB, HeightsArgs.PassageNodesMaxLevel, 0, MaxLevelTransition); } } } } clsPassageNode tmpPassageNodeC = default(clsPassageNode); App.sResult Result = new App.sResult(); HeightsArgs.FlatsCutoff = 1; HeightsArgs.PassagesCutoff = 1; HeightsArgs.VariationCutoff = 1; HeightsArgs.ActionTotal = 1; for ( A = 0; A <= PassageNodeCount - 1; A++ ) { tmpPassageNodeA = PassageNodeOrder[A]; if ( tmpPassageNodeA.Level < 0 && !tmpPassageNodeA.IsOnBorder && tmpPassageNodeA.IsNearBorder ) { HeightsArgs.PassageNode = tmpPassageNodeA; Result = PassageNodeHeightLevel(HeightsArgs); if ( !Result.Success ) { ReturnResult.ProblemAdd(Result.Problem); return ReturnResult; } } } HeightsArgs.FlatsCutoff = FlatsChance; HeightsArgs.PassagesCutoff = HeightsArgs.FlatsCutoff + PassagesChance; HeightsArgs.VariationCutoff = HeightsArgs.PassagesCutoff + VariationChance; HeightsArgs.ActionTotal = HeightsArgs.VariationCutoff; if ( HeightsArgs.ActionTotal <= 0 ) { ReturnResult.ProblemAdd("All height level behaviors are zero"); return ReturnResult; } for ( A = 0; A <= PassageNodeCount - 1; A++ ) { tmpPassageNodeA = PassageNodeOrder[A]; if ( tmpPassageNodeA.Level < 0 && !tmpPassageNodeA.IsOnBorder ) { HeightsArgs.PassageNode = tmpPassageNodeA; Result = PassageNodeHeightLevel(HeightsArgs); if ( !Result.Success ) { ReturnResult.ProblemAdd(Result.Problem); return ReturnResult; } } } //set edge points to the level of their neighbour for ( A = 0; A <= PassageNodeCount - 1; A++ ) { tmpPassageNodeA = PassageNodes[0, A]; if ( tmpPassageNodeA.IsOnBorder ) { if ( tmpPassageNodeA.Level >= 0 ) { ReturnResult.ProblemAdd("Error: Border has had its height set."); return ReturnResult; } //If tmpPassageNodeA.ConnectionCount <> 1 Then // ReturnResult.Problem = "Error: Border has incorrect connections." // Exit Function //End If tmpPassageNodeC = null; CanDoFlatsAroundWater = true; for ( B = 0; B <= tmpPassageNodeA.ConnectionCount - 1; B++ ) { tmpPassageNodeB = tmpPassageNodeA.Connections[B].GetOther(); if ( tmpPassageNodeB.Level >= 0 && !tmpPassageNodeB.IsOnBorder ) { if ( HeightsArgs.PassageNodesMinLevel.Nodes[tmpPassageNodeA.Num] <= tmpPassageNodeB.Level && HeightsArgs.PassageNodesMaxLevel.Nodes[tmpPassageNodeA.Num] >= tmpPassageNodeB.Level ) { if ( tmpPassageNodeC == null ) { tmpPassageNodeC = tmpPassageNodeB; } } } if ( HeightsArgs.PassageNodesMinLevel.Nodes[tmpPassageNodeB.Num] > 0 ) { CanDoFlatsAroundWater = false; } } //If tmpPassageNodeC Is Nothing Then // ReturnResult.Problem_Add("Error: No connection for border node") // Return ReturnResult //End If if ( tmpPassageNodeC != null ) { BestNum = tmpPassageNodeC.Level; PassageNodesMinLevelSet(tmpPassageNodeA, HeightsArgs.PassageNodesMinLevel, BestNum, MaxLevelTransition); PassageNodesMaxLevelSet(tmpPassageNodeA, HeightsArgs.PassageNodesMaxLevel, BestNum, MaxLevelTransition); for ( D = 0; D <= SymmetryBlockCount - 1; D++ ) { PassageNodes[D, A].IsWater = tmpPassageNodeC.IsWater && CanDoFlatsAroundWater; PassageNodes[D, A].Level = BestNum; } if ( tmpPassageNodeA.IsWater ) { for ( B = 0; B <= tmpPassageNodeA.ConnectionCount - 1; B++ ) { tmpPassageNodeB = tmpPassageNodeA.Connections[B].GetOther(); PassageNodesMinLevelSet(tmpPassageNodeB, HeightsArgs.PassageNodesMinLevel, tmpPassageNodeA.Level, MaxLevelTransition); PassageNodesMaxLevelSet(tmpPassageNodeB, HeightsArgs.PassageNodesMaxLevel, tmpPassageNodeA.Level, MaxLevelTransition); } } } } else if ( tmpPassageNodeA.Level < 0 ) { ReturnResult.ProblemAdd("Error: Node height not set"); return ReturnResult; } } //set level of edge points only connected to another border point for ( A = 0; A <= PassageNodeCount - 1; A++ ) { tmpPassageNodeA = PassageNodes[0, A]; if ( tmpPassageNodeA.IsOnBorder && tmpPassageNodeA.Level < 0 ) { tmpPassageNodeC = null; CanDoFlatsAroundWater = true; for ( B = 0; B <= tmpPassageNodeA.ConnectionCount - 1; B++ ) { tmpPassageNodeB = tmpPassageNodeA.Connections[B].GetOther(); if ( tmpPassageNodeB.Level >= 0 ) { if ( HeightsArgs.PassageNodesMinLevel.Nodes[tmpPassageNodeA.Num] <= tmpPassageNodeB.Level && HeightsArgs.PassageNodesMaxLevel.Nodes[tmpPassageNodeA.Num] >= tmpPassageNodeB.Level ) { if ( tmpPassageNodeC == null ) { tmpPassageNodeC = tmpPassageNodeB; } } } if ( HeightsArgs.PassageNodesMinLevel.Nodes[tmpPassageNodeB.Num] > 0 ) { CanDoFlatsAroundWater = false; } } if ( tmpPassageNodeC == null ) { ReturnResult.ProblemAdd("Error: No connection for border node"); return ReturnResult; } BestNum = tmpPassageNodeC.Level; PassageNodesMinLevelSet(tmpPassageNodeA, HeightsArgs.PassageNodesMinLevel, BestNum, MaxLevelTransition); PassageNodesMaxLevelSet(tmpPassageNodeA, HeightsArgs.PassageNodesMaxLevel, BestNum, MaxLevelTransition); for ( D = 0; D <= SymmetryBlockCount - 1; D++ ) { PassageNodes[D, A].IsWater = tmpPassageNodeC.IsWater && CanDoFlatsAroundWater; PassageNodes[D, A].Level = BestNum; } if ( tmpPassageNodeA.IsWater ) { for ( B = 0; B <= tmpPassageNodeA.ConnectionCount - 1; B++ ) { tmpPassageNodeB = tmpPassageNodeA.Connections[B].GetOther(); PassageNodesMinLevelSet(tmpPassageNodeB, HeightsArgs.PassageNodesMinLevel, tmpPassageNodeA.Level, MaxLevelTransition); PassageNodesMaxLevelSet(tmpPassageNodeB, HeightsArgs.PassageNodesMaxLevel, tmpPassageNodeA.Level, MaxLevelTransition); } } } } RampBase = 1.0D; MaxDisconnectionDist = 99999.0F; clsResult RampResult = GenerateRamps(); ReturnResult.Add(RampResult); return ReturnResult; }
public clsResult GenerateRamps() { clsResult ReturnResult = new clsResult("Ramps"); int A = 0; int B = 0; int C = 0; int E = 0; double BestDist = 0; int BestNum = 0; sXY_int XY_int = new sXY_int(); clsPassageNode tmpPassageNodeA = default(clsPassageNode); clsPassageNode tmpPassageNodeB = default(clsPassageNode); double Dist = 0; //make ramps for ( A = 0; A <= ConnectionCount - 1; A++ ) { Connections[A].IsRamp = false; } PathfinderNode tmpNodeA = default(PathfinderNode); PathfinderNode tmpNodeB = default(PathfinderNode); PathfinderNode[,] PassageNodePathNodes = null; PathfinderConnection NewConnection; clsPassageNodeNework PassageNodeNetwork = MakePassageNodeNetwork(); PassageNodePathNodes = PassageNodeNetwork.PassageNodePathNodes; clsConnection[] PossibleRamps = new clsConnection[ConnectionCount]; int PossibleRampCount = 0; PathfinderNode[] GetPathStartNodes = new PathfinderNode[1]; PathfinderNetwork.PathList[] ResultPaths = null; //ramp connections whose points are too far apart bool[] ConnectionsCanRamp = new bool[ConnectionCount]; for ( B = 0; B <= ConnectionCount - 1; B++ ) { C = Math.Abs(Connections[B].PassageNodeA.Level - Connections[B].PassageNodeB.Level); if ( C == 1 ) { if ( !(Connections[B].PassageNodeA.IsOnBorder || Connections[B].PassageNodeB.IsOnBorder) && Connections[B].PassageNodeA.MirrorNum == 0 && Connections[B].PassageNodeA.Num != Connections[B].PassageNodeB.Num ) { ConnectionsCanRamp[B] = true; } else { ConnectionsCanRamp[B] = false; } } else { ConnectionsCanRamp[B] = false; } } clsNodeConnectedness Connectedness = new clsNodeConnectedness(); Connectedness.NodeConnectedness = new float[PassageNodeCount]; Connectedness.PassageNodeVisited = new bool[SymmetryBlockCount, PassageNodeCount]; Connectedness.PassageNodePathNodes = PassageNodePathNodes; Connectedness.PassageNodePathMap = PassageNodeNetwork.Network; PathfinderConnection[] tmpPathConnection = new PathfinderConnection[4]; double Value = 0; double BestDistB = 0; double BaseDist = 0; double RampDist = 0; clsUpdateNodeConnectednessArgs UpdateNodeConnectednessArgs = new clsUpdateNodeConnectednessArgs(); clsUpdateNetworkConnectednessArgs UpdateNetworkConnectednessArgs = new clsUpdateNetworkConnectednessArgs(); UpdateNodeConnectednessArgs.Args = Connectedness; UpdateNetworkConnectednessArgs.Args = Connectedness; UpdateNetworkConnectednessArgs.PassageNodeUpdated = new bool[PassageNodeCount]; UpdateNetworkConnectednessArgs.SymmetryBlockCount = SymmetryBlockCount; for ( A = 0; A <= PassageNodeCount - 1; A++ ) { Connectedness.NodeConnectedness[A] = 0.0F; for ( B = 0; B <= PassageNodeCount - 1; B++ ) { for ( C = 0; C <= SymmetryBlockCount - 1; C++ ) { Connectedness.PassageNodeVisited[C, B] = false; } } UpdateNodeConnectednessArgs.OriginalNode = PassageNodes[0, A]; UpdateNodeConnectedness(UpdateNodeConnectednessArgs, PassageNodes[0, A]); } do { BestNum = -1; BestDist = 1.0F; //for connections that can already reach the other side BestDistB = 0.0F; //for connections that cant PossibleRampCount = 0; for ( B = 0; B <= ConnectionCount - 1; B++ ) { if ( ConnectionsCanRamp[B] && !Connections[B].IsRamp ) { if ( CheckRampAngles(Connections[B], Convert.ToDouble(80.0D * MathUtil.RadOf1Deg), Convert.ToDouble(120.0D * MathUtil.RadOf1Deg), 0.0D * MathUtil.RadOf1Deg) ) { GetPathStartNodes[0] = PassageNodePathNodes[Connections[B].PassageNodeA.MirrorNum, Connections[B].PassageNodeA.Num]; ResultPaths = PassageNodeNetwork.Network.GetPath(GetPathStartNodes, PassageNodePathNodes[Connections[B].PassageNodeB.MirrorNum, Connections[B].PassageNodeB.Num], -1, 0); BaseDist = double.MaxValue; XY_int.X = (int)((Connections[B].PassageNodeA.Pos.X + Connections[B].PassageNodeB.Pos.X) / 2.0D); XY_int.Y = (int)((Connections[B].PassageNodeA.Pos.Y + Connections[B].PassageNodeB.Pos.Y) / 2.0D); for ( E = 0; E <= TotalPlayerCount - 1; E++ ) { Dist = Convert.ToDouble((PlayerBases[E].Pos - XY_int).ToDoubles().GetMagnitude()); if ( Dist < BaseDist ) { BaseDist = Dist; } } RampDist = Math.Max(MaxDisconnectionDist * Math.Pow(RampBase, (BaseDist / 1024.0D)), 1.0F); if ( ResultPaths == null ) { Value = Connectedness.NodeConnectedness[Connections[B].PassageNodeA.Num] + Connectedness.NodeConnectedness[Connections[B].PassageNodeB.Num]; if ( double.MaxValue > BestDist ) { BestDist = double.MaxValue; BestDistB = Value; PossibleRamps[0] = Connections[B]; PossibleRampCount = 1; } else { if ( Value < BestDistB ) { BestDistB = Value; PossibleRamps[0] = Connections[B]; PossibleRampCount = 1; } else if ( Value == BestDistB ) { PossibleRamps[PossibleRampCount] = Connections[B]; PossibleRampCount++; } } } else if ( ResultPaths[0].PathCount != 1 ) { ReturnResult.ProblemAdd("Error: Invalid number of routes returned."); goto Finish; } else if ( ResultPaths[0].Paths[0].Value / RampDist > BestDist ) { BestDist = ResultPaths[0].Paths[0].Value / RampDist; PossibleRamps[0] = Connections[B]; PossibleRampCount = 1; } else if ( ResultPaths[0].Paths[0].Value / RampDist == BestDist ) { PossibleRamps[PossibleRampCount] = Connections[B]; PossibleRampCount++; } else if ( ResultPaths[0].Paths[0].Value <= RampDist ) { ConnectionsCanRamp[B] = false; } } else { ConnectionsCanRamp[B] = false; } } else { ConnectionsCanRamp[B] = false; } } if ( PossibleRampCount > 0 ) { BestNum = (int)(Conversion.Int(VBMath.Rnd() * PossibleRampCount)); PossibleRamps[BestNum].IsRamp = true; tmpPassageNodeA = PossibleRamps[BestNum].PassageNodeA; tmpPassageNodeB = PossibleRamps[BestNum].PassageNodeB; tmpNodeA = PassageNodePathNodes[tmpPassageNodeA.MirrorNum, tmpPassageNodeA.Num]; tmpNodeB = PassageNodePathNodes[tmpPassageNodeB.MirrorNum, tmpPassageNodeB.Num]; NewConnection = tmpNodeA.CreateConnection(tmpNodeB, GetNodePosDist(tmpNodeA, tmpNodeB)); for ( C = 0; C <= PossibleRamps[BestNum].ReflectionCount - 1; C++ ) { PossibleRamps[BestNum].Reflections[C].IsRamp = true; tmpPassageNodeA = PossibleRamps[BestNum].Reflections[C].PassageNodeA; tmpPassageNodeB = PossibleRamps[BestNum].Reflections[C].PassageNodeB; tmpNodeA = PassageNodePathNodes[tmpPassageNodeA.MirrorNum, tmpPassageNodeA.Num]; tmpNodeB = PassageNodePathNodes[tmpPassageNodeB.MirrorNum, tmpPassageNodeB.Num]; NewConnection = tmpNodeA.CreateConnection(tmpNodeB, GetNodePosDist(tmpNodeA, tmpNodeB)); } PassageNodeNetwork.Network.FindCalc(); for ( E = 0; E <= PassageNodeCount - 1; E++ ) { UpdateNetworkConnectednessArgs.PassageNodeUpdated[E] = false; } if ( PossibleRamps[BestNum].PassageNodeA.MirrorNum == 0 ) { UpdateNetworkConnectedness(UpdateNetworkConnectednessArgs, PossibleRamps[BestNum].PassageNodeA); } else if ( PossibleRamps[BestNum].PassageNodeB.MirrorNum == 0 ) { UpdateNetworkConnectedness(UpdateNetworkConnectednessArgs, PossibleRamps[BestNum].PassageNodeB); } else { ReturnResult.ProblemAdd("Error: Initial ramp not in area 0."); goto Finish; } } else { break; } } while ( true ); PathfinderNetwork.sFloodProximityArgs FloodArgs = new PathfinderNetwork.sFloodProximityArgs(); FloodArgs.StartNode = PassageNodeNetwork.PassageNodePathNodes[0, 0]; FloodArgs.NodeValues = PassageNodeNetwork.Network.NetworkLargeArrays.Nodes_ValuesA; for ( A = 0; A <= PassageNodeCount - 1; A++ ) { for ( B = 0; B <= SymmetryBlockCount - 1; B++ ) { FloodArgs.NodeValues[PassageNodeNetwork.PassageNodePathNodes[B, A].Layer_NodeNum] = float.MaxValue; } } PassageNodeNetwork.Network.FloodProximity(FloodArgs); for ( A = 0; A <= PassageNodeCount - 1; A++ ) { for ( B = 0; B <= SymmetryBlockCount - 1; B++ ) { if ( !PassageNodes[B, A].IsWater ) { if ( FloodArgs.NodeValues[PassageNodeNetwork.PassageNodePathNodes[B, A].Layer_NodeNum] == float.MaxValue ) { ReturnResult.ProblemAdd("Land is unreachable. Reduce variation or retry."); goto Finish; } } } } Finish: PassageNodeNetwork.Network.Deallocate(); return ReturnResult; }
private bool CheckRampAngles(clsConnection NewRampConnection, double MinSpacingAngle, double MinSpacingAngle2, double MinPassageSpacingAngle) { sXY_int XY_int = new sXY_int(); double NodeAAwayAngle = 0; double NodeBAwayAngle = 0; XY_int.X = NewRampConnection.PassageNodeB.Pos.X - NewRampConnection.PassageNodeA.Pos.X; XY_int.Y = NewRampConnection.PassageNodeB.Pos.Y - NewRampConnection.PassageNodeA.Pos.Y; if ( NewRampConnection.PassageNodeA.Connections[NewRampConnection.PassageNodeA_ConnectionNum].IsB ) { NodeBAwayAngle = XY_int.ToDoubles().GetAngle(); NodeAAwayAngle = MathUtil.AngleClamp(NodeBAwayAngle - Math.PI); } else { NodeAAwayAngle = XY_int.ToDoubles().GetAngle(); NodeBAwayAngle = MathUtil.AngleClamp(NodeBAwayAngle - Math.PI); } if ( !CheckRampNodeRampAngles(NewRampConnection.PassageNodeA, NewRampConnection.PassageNodeB, NodeAAwayAngle, MinSpacingAngle, MinSpacingAngle2) ) { return false; } if ( !CheckRampNodeRampAngles(NewRampConnection.PassageNodeB, NewRampConnection.PassageNodeA, NodeBAwayAngle, MinSpacingAngle, MinSpacingAngle2) ) { return false; } if ( !CheckRampNodeLevelAngles(NewRampConnection.PassageNodeA, NodeAAwayAngle, MinPassageSpacingAngle) ) { return false; } if ( !CheckRampNodeLevelAngles(NewRampConnection.PassageNodeB, NodeBAwayAngle, MinPassageSpacingAngle) ) { return false; } return true; }
public clsResult GenerateRamps() { int num; int num6; int num7; int num9; clsResult result2 = new clsResult("Ramps"); int num13 = this.ConnectionCount - 1; for (num = 0; num <= num13; num++) { this.Connections[num].IsRamp = false; } clsPassageNodeNework nework = this.MakePassageNodeNetwork(); PathfinderNode[,] passageNodePathNodes = nework.PassageNodePathNodes; clsConnection[] connectionArray = new clsConnection[(this.ConnectionCount - 1) + 1]; PathfinderNode[] startNodes = new PathfinderNode[1]; bool[] flagArray = new bool[(this.ConnectionCount - 1) + 1]; int num14 = this.ConnectionCount - 1; int index = 0; while (index <= num14) { if (Math.Abs((int) (this.Connections[index].PassageNodeA.Level - this.Connections[index].PassageNodeB.Level)) == 1) { if ((!(this.Connections[index].PassageNodeA.IsOnBorder | this.Connections[index].PassageNodeB.IsOnBorder) & (this.Connections[index].PassageNodeA.MirrorNum == 0)) & (this.Connections[index].PassageNodeA.Num != this.Connections[index].PassageNodeB.Num)) { flagArray[index] = true; } else { flagArray[index] = false; } } else { flagArray[index] = false; } index++; } clsNodeConnectedness connectedness = new clsNodeConnectedness { NodeConnectedness = new float[(this.PassageNodeCount - 1) + 1], PassageNodeVisited = new bool[(this.SymmetryBlockCount - 1) + 1, (this.PassageNodeCount - 1) + 1], PassageNodePathNodes = passageNodePathNodes, PassageNodePathMap = nework.Network }; PathfinderConnection[] connectionArray2 = new PathfinderConnection[4]; clsUpdateNodeConnectednessArgs args3 = new clsUpdateNodeConnectednessArgs(); clsUpdateNetworkConnectednessArgs args2 = new clsUpdateNetworkConnectednessArgs(); args3.Args = connectedness; args2.Args = connectedness; args2.PassageNodeUpdated = new bool[(this.PassageNodeCount - 1) + 1]; args2.SymmetryBlockCount = this.SymmetryBlockCount; int num15 = this.PassageNodeCount - 1; for (num = 0; num <= num15; num++) { connectedness.NodeConnectedness[num] = 0f; int num16 = this.PassageNodeCount - 1; for (index = 0; index <= num16; index++) { int num17 = this.SymmetryBlockCount - 1; num7 = 0; while (num7 <= num17) { connectedness.PassageNodeVisited[num7, index] = false; num7++; } } args3.OriginalNode = this.PassageNodes[0, num]; this.UpdateNodeConnectedness(args3, this.PassageNodes[0, num]); } Label_0269: num6 = -1; double num4 = 1.0; double num5 = 0.0; int num10 = 0; int num18 = this.ConnectionCount - 1; index = 0; while (index <= num18) { if (flagArray[index] & !this.Connections[index].IsRamp) { if (this.CheckRampAngles(this.Connections[index], 1.3962634015954636, 2.0943951023931953, 0.0)) { modMath.sXY_int _int; startNodes[0] = passageNodePathNodes[this.Connections[index].PassageNodeA.MirrorNum, this.Connections[index].PassageNodeA.Num]; PathfinderNetwork.PathList[] listArray = nework.Network.GetPath(startNodes, passageNodePathNodes[this.Connections[index].PassageNodeB.MirrorNum, this.Connections[index].PassageNodeB.Num], -1, 0); double maxValue = double.MaxValue; _int.X = (int) Math.Round((double) (((double) (this.Connections[index].PassageNodeA.Pos.X + this.Connections[index].PassageNodeB.Pos.X)) / 2.0)); _int.Y = (int) Math.Round((double) (((double) (this.Connections[index].PassageNodeA.Pos.Y + this.Connections[index].PassageNodeB.Pos.Y)) / 2.0)); int num19 = this.TotalPlayerCount - 1; num9 = 0; while (num9 <= num19) { modMath.sXY_int _int2 = this.PlayerBases[num9].Pos - _int; double magnitude = _int2.ToDoubles().GetMagnitude(); if (magnitude < maxValue) { maxValue = magnitude; } num9++; } double num11 = Math.Max((double) (this.MaxDisconnectionDist * Math.Pow(this.RampBase, maxValue / 1024.0)), (double) 1.0); if (listArray == null) { double num12 = connectedness.NodeConnectedness[this.Connections[index].PassageNodeA.Num] + connectedness.NodeConnectedness[this.Connections[index].PassageNodeB.Num]; if (double.MaxValue > num4) { num4 = double.MaxValue; num5 = num12; connectionArray[0] = this.Connections[index]; num10 = 1; } else if (num12 < num5) { num5 = num12; connectionArray[0] = this.Connections[index]; num10 = 1; } else if (num12 == num5) { connectionArray[num10] = this.Connections[index]; num10++; } } else { if (listArray[0].PathCount != 1) { result2.ProblemAdd("Error: Invalid number of routes returned."); goto Label_088A; } if ((((double) listArray[0].Paths[0].Value) / num11) > num4) { num4 = ((double) listArray[0].Paths[0].Value) / num11; connectionArray[0] = this.Connections[index]; num10 = 1; } else if ((((double) listArray[0].Paths[0].Value) / num11) == num4) { connectionArray[num10] = this.Connections[index]; num10++; } else if (listArray[0].Paths[0].Value <= num11) { flagArray[index] = false; } } } else { flagArray[index] = false; } } else { flagArray[index] = false; } index++; } if (num10 > 0) { num6 = (int) Math.Round((double) ((float) (App.Random.Next() * num10))); connectionArray[num6].IsRamp = true; clsPassageNode passageNodeA = connectionArray[num6].PassageNodeA; clsPassageNode passageNodeB = connectionArray[num6].PassageNodeB; PathfinderNode nodeA = passageNodePathNodes[passageNodeA.MirrorNum, passageNodeA.Num]; PathfinderNode otherNode = passageNodePathNodes[passageNodeB.MirrorNum, passageNodeB.Num]; PathfinderConnection connection = nodeA.CreateConnection(otherNode, this.GetNodePosDist(nodeA, otherNode)); int num20 = connectionArray[num6].ReflectionCount - 1; for (num7 = 0; num7 <= num20; num7++) { connectionArray[num6].Reflections[num7].IsRamp = true; passageNodeA = connectionArray[num6].Reflections[num7].PassageNodeA; passageNodeB = connectionArray[num6].Reflections[num7].PassageNodeB; nodeA = passageNodePathNodes[passageNodeA.MirrorNum, passageNodeA.Num]; otherNode = passageNodePathNodes[passageNodeB.MirrorNum, passageNodeB.Num]; connection = nodeA.CreateConnection(otherNode, this.GetNodePosDist(nodeA, otherNode)); } nework.Network.FindCalc(); int num21 = this.PassageNodeCount - 1; for (num9 = 0; num9 <= num21; num9++) { args2.PassageNodeUpdated[num9] = false; } if (connectionArray[num6].PassageNodeA.MirrorNum == 0) { this.UpdateNetworkConnectedness(args2, connectionArray[num6].PassageNodeA); goto Label_0269; } if (connectionArray[num6].PassageNodeB.MirrorNum == 0) { this.UpdateNetworkConnectedness(args2, connectionArray[num6].PassageNodeB); goto Label_0269; } result2.ProblemAdd("Error: Initial ramp not in area 0."); } else { PathfinderNetwork.sFloodProximityArgs args; args.StartNode = nework.PassageNodePathNodes[0, 0]; args.NodeValues = nework.Network.NetworkLargeArrays.Nodes_ValuesA; int num22 = this.PassageNodeCount - 1; for (num = 0; num <= num22; num++) { int num23 = this.SymmetryBlockCount - 1; index = 0; while (index <= num23) { args.NodeValues[nework.PassageNodePathNodes[index, num].Layer_NodeNum] = float.MaxValue; index++; } } nework.Network.FloodProximity(ref args); int num24 = this.PassageNodeCount - 1; for (num = 0; num <= num24; num++) { int num25 = this.SymmetryBlockCount - 1; for (index = 0; index <= num25; index++) { if (!this.PassageNodes[index, num].IsWater && (args.NodeValues[nework.PassageNodePathNodes[index, num].Layer_NodeNum] == float.MaxValue)) { result2.ProblemAdd("Land is unreachable. Reduce variation or retry."); break; } } } } Label_088A: nework.Network.Deallocate(); return result2; }
private bool CheckRampAngles(clsConnection NewRampConnection, double MinSpacingAngle, double MinSpacingAngle2, double MinPassageSpacingAngle) { double num; double angle; modMath.sXY_int _int; _int.X = NewRampConnection.PassageNodeB.Pos.X - NewRampConnection.PassageNodeA.Pos.X; _int.Y = NewRampConnection.PassageNodeB.Pos.Y - NewRampConnection.PassageNodeA.Pos.Y; if (NewRampConnection.PassageNodeA.Connections[NewRampConnection.PassageNodeA_ConnectionNum].IsB) { angle = _int.ToDoubles().GetAngle(); num = modMath.AngleClamp(angle - 3.1415926535897931); } else { num = _int.ToDoubles().GetAngle(); angle = modMath.AngleClamp(angle - 3.1415926535897931); } if (!this.CheckRampNodeRampAngles(NewRampConnection.PassageNodeA, NewRampConnection.PassageNodeB, num, MinSpacingAngle, MinSpacingAngle2)) { return false; } if (!this.CheckRampNodeRampAngles(NewRampConnection.PassageNodeB, NewRampConnection.PassageNodeA, angle, MinSpacingAngle, MinSpacingAngle2)) { return false; } if (!this.CheckRampNodeLevelAngles(NewRampConnection.PassageNodeA, num, MinPassageSpacingAngle)) { return false; } if (!this.CheckRampNodeLevelAngles(NewRampConnection.PassageNodeB, angle, MinPassageSpacingAngle)) { return false; } return true; }