diff --git a/MissionEditor/FinalSunDlg.cpp b/MissionEditor/FinalSunDlg.cpp index 73514c2..197b953 100644 --- a/MissionEditor/FinalSunDlg.cpp +++ b/MissionEditor/FinalSunDlg.cpp @@ -893,7 +893,7 @@ void CFinalSunDlg::SaveMap(CString FileName_) for (i = 0; i < Map->GetWaypointCount(); i++) { CString id; DWORD pos; - Map->GetWaypointData(i, &id, &pos); + Map->GetNthWaypointData(i, &id, &pos); int idi; idi = atoi(id); if (idi != i) break; @@ -1055,7 +1055,7 @@ void CFinalSunDlg::SaveMap(CString FileName_) for (i = 0; i < Map->GetWaypointCount(); i++) { CString id; DWORD pos; - Map->GetWaypointData(i, &id, &pos); + Map->GetNthWaypointData(i, &id, &pos); int idi; idi = atoi(id); if (idi != i) { @@ -1822,8 +1822,8 @@ void CFinalSunDlg::OnFileNew() last_succeeded_operation = 11003; // create map function was created for SP. Fix it here; - Map->DeleteWaypoint(0); - Map->DeleteWaypoint(0); + Map->DeleteWaypoint(98); + Map->DeleteWaypoint(99); int midx = Map->GetIsoSize() / 2; int midy = Map->GetIsoSize() / 2; Map->AddWaypoint("0", midx + midy * Map->GetIsoSize()); diff --git a/MissionEditor/IsoView.cpp b/MissionEditor/IsoView.cpp index efaad42..98b9018 100644 --- a/MissionEditor/IsoView.cpp +++ b/MissionEditor/IsoView.cpp @@ -1567,7 +1567,7 @@ void CIsoView::OnMouseMove(UINT nFlags, CPoint point) for (i = 0; i < Map->GetWaypointCount(); i++) { CString id; DWORD pos; - Map->GetWaypointData(i, &id, &pos); + Map->GetNthWaypointData(i, &id, &pos); if (atoi(id) == e) bFound = TRUE; if (bFound) break; } @@ -6151,7 +6151,7 @@ void CIsoView::FocusWaypoint(int index) DWORD dwPos; - Map->GetWaypointData(index, NULL, &dwPos); + Map->GetNthWaypointData(index, NULL, &dwPos); x = dwPos % Map->GetIsoSize(); y = dwPos / Map->GetIsoSize(); diff --git a/MissionEditor/MapData.cpp b/MissionEditor/MapData.cpp index 2b1f3f4..ae431af 100644 --- a/MissionEditor/MapData.cpp +++ b/MissionEditor/MapData.cpp @@ -1872,15 +1872,11 @@ void CMapData::DeleteInfantry(DWORD dwIndex) } -void CMapData::DeleteWaypoint(DWORD dwIndex) +void CMapData::DeleteWaypoint(DWORD dwId) { - if (dwIndex >= GetWaypointCount()) { - return; - } - CString id; DWORD pos; - Map->GetWaypointData(dwIndex, &id, &pos); + Map->GetWaypointData(dwId, &id, &pos); int x = pos % m_IsoSize; int y = pos / m_IsoSize; @@ -1895,9 +1891,11 @@ void CMapData::DeleteWaypoint(DWORD dwIndex) } int k, l; - for (k = -1; k < 2; k++) - for (l = -1; l < 2; l++) + for (k = -1; k < 2; k++) { + for (l = -1; l < 2; l++) { Mini_UpdatePos(x + k, y + l, IsMultiplayer()); + } + } } void CMapData::DeleteCelltag(DWORD dwIndex) @@ -2771,7 +2769,7 @@ BOOL CMapData::IsGroundObjectAt(DWORD dwPos) const } -void CMapData::GetWaypointData(DWORD dwIndex, CString* lpID, DWORD* lpdwPos) const +void CMapData::GetNthWaypointData(DWORD dwIdx, CString* lpID, DWORD* lpdwPos) const { if (lpID) { *lpID = ""; @@ -2780,11 +2778,7 @@ void CMapData::GetWaypointData(DWORD dwIndex, CString* lpID, DWORD* lpdwPos) con *lpdwPos = 0; } - auto const& section = m_mapfile.GetSection("Waypoints"); - CString id; - id.Format("%d", dwIndex); - - auto const& data = section.GetString(id); + auto const& [id, data] = m_mapfile.GetSection("Waypoints").Nth(dwIdx); if (data.IsEmpty()) { return; @@ -2801,6 +2795,26 @@ void CMapData::GetWaypointData(DWORD dwIndex, CString* lpID, DWORD* lpdwPos) con } } +void CMapData::GetWaypointData(DWORD dwId, CString* lpID, DWORD* lpdwPos) const +{ + if (lpID) { + *lpID = ""; + } + if (lpdwPos) { + *lpdwPos = 0; + } + + CString id; + id.Format("%d", dwId); + auto const& section = m_mapfile.GetSection("Waypoints"); + + auto const idx = section.FindIndex(id); + + if (idx >= 0 && idx < section.Size()) { + GetNthWaypointData(idx, lpID, lpdwPos); + } +} + void CMapData::GetStdAircraftData(DWORD dwIndex, STDOBJECTDATA* lpStdAircraft) const { auto const& section = m_mapfile.GetSection("Aircraft"); @@ -6094,7 +6108,7 @@ void CMapData::ResizeMap(int iLeft, int iTop, DWORD dwNewWidth, DWORD dwNewHeigh DWORD pos; CString id; - GetWaypointData(i, &id, &pos); + GetNthWaypointData(i, &id, &pos); wp_id[i] = id; wp_pos[i] = pos; diff --git a/MissionEditor/MapData.h b/MissionEditor/MapData.h index 8e8fd29..be9c8a2 100644 --- a/MissionEditor/MapData.h +++ b/MissionEditor/MapData.h @@ -387,7 +387,8 @@ public: DWORD GetInfantryCount() const; void GetStdUnitData(DWORD dwIndex, STDOBJECTDATA* lpStdUnit) const; void GetStdAircraftData(DWORD dwIndex, STDOBJECTDATA* lpStdAircraft) const; - void GetWaypointData(DWORD dwIndex, CString* lpID, DWORD* lpdwPos) const; + void GetNthWaypointData(DWORD dwIdx, CString* lpID, DWORD* lpdwPos) const; + void GetWaypointData(DWORD dwId, CString* lpID, DWORD* lpdwPos) const; BOOL IsGroundObjectAt(DWORD dwPos) const; BOOL AddTerrain(LPCTSTR lpType, DWORD dwPos, int suggestedIndex = -1); void GetTerrainData(DWORD dwIndex, CString* lpType) const; @@ -415,7 +416,7 @@ public: void DeleteStructure(DWORD dwIndex); void DeleteUnit(DWORD dwIndex); void DeleteCelltag(DWORD dwIndex); - void DeleteWaypoint(DWORD dwIndex); + void DeleteWaypoint(DWORD id); void DeleteInfantry(DWORD dwIndex); INT GetCelltagAt(DWORD dwPos) const diff --git a/MissionEditor/MapValidator.cpp b/MissionEditor/MapValidator.cpp index 6919005..a710473 100644 --- a/MissionEditor/MapValidator.cpp +++ b/MissionEditor/MapValidator.cpp @@ -159,7 +159,7 @@ BOOL CMapValidator::CheckMap() for (i = 0; i < d; i++) { DWORD pos; CString id; - Map->GetWaypointData(i, &id, &pos); + Map->GetNthWaypointData(i, &id, &pos); if (atoi(id) < 8) { below8found++; } @@ -328,9 +328,11 @@ BOOL CMapValidator::CheckMap() DWORD pos; CString id; - Map->GetWaypointData(i, &id, &pos); + Map->GetNthWaypointData(i, &id, &pos); - if (atoi(id) > 99) bWaypBig = TRUE; + if (atoi(id) > 99) { + bWaypBig = TRUE; + } } if (bWaypBig) diff --git a/MissionEditor/SearchWaypointDlg.cpp b/MissionEditor/SearchWaypointDlg.cpp index f32c5de..617dae6 100644 --- a/MissionEditor/SearchWaypointDlg.cpp +++ b/MissionEditor/SearchWaypointDlg.cpp @@ -76,7 +76,7 @@ BOOL CSearchWaypointDlg::OnInitDialog() for (i = 0; i < count; i++) { CString id; DWORD pos; - Map->GetWaypointData(i, &id, &pos); + Map->GetNthWaypointData(i, &id, &pos); ctrl.SetItemData(ctrl.InsertString(i, id), i); } diff --git a/MissionEditor/UserScriptsDlg.cpp b/MissionEditor/UserScriptsDlg.cpp index 4a6e8b0..e0810a6 100644 --- a/MissionEditor/UserScriptsDlg.cpp +++ b/MissionEditor/UserScriptsDlg.cpp @@ -577,7 +577,7 @@ int get_player_count() for (i = 0; i < Map->GetWaypointCount(); i++) { CString id; DWORD pos; - Map->GetWaypointData(i, &id, &pos); + Map->GetNthWaypointData(i, &id, &pos); int idi; idi = atoi(id); if (idi != i) break; @@ -1983,7 +1983,7 @@ void CUserScriptsDlg::OnOK() int k; for (k = 0; k < Map->GetWaypointCount(); k++) { CString id; - Map->GetWaypointData(k, &id, &pos); + Map->GetNthWaypointData(k, &id, &pos); if (id == params[0]) { bFound = TRUE;