diff --git a/MissionEditor/IsoView.cpp b/MissionEditor/IsoView.cpp index 7579edb..870b414 100644 --- a/MissionEditor/IsoView.cpp +++ b/MissionEditor/IsoView.cpp @@ -2205,7 +2205,9 @@ void CIsoView::HandleProperties(int n, int type) { CIniFile& ini = Map->GetIniFile(); - if (n < 0) return; + if (n < 0) { + return; + } switch (type) { case 0: { @@ -2222,18 +2224,20 @@ void CIsoView::HandleProperties(int n, int type) CInfantrie dlg(this); char tmp[255]; - dlg.Init((LPCTSTR)data.house, (LPCTSTR)data.strength, (LPCTSTR)data.action, - (LPCTSTR)data.direction, (LPCTSTR)data.tag, (LPCTSTR)data.flag1, - (LPCTSTR)data.group, (LPCTSTR)data.flag3, (LPCTSTR)data.flag4, (LPCTSTR)data.flag5); + dlg.Init(data.basic.house, data.basic.strength, data.action, + data.direction, data.tag, data.flag1, + data.group, data.flag3, data.flag4, data.flag5); int res = dlg.DoModal(); - if (res == IDCANCEL) return; + if (res == IDCANCEL) { + return; + } data.action = dlg.m_action; - data.strength = dlg.m_strength; + data.basic.strength = dlg.m_strength; data.tag = dlg.m_tag; data.direction = dlg.m_direction; - data.house = dlg.m_house; + data.basic.house = dlg.m_house; data.flag1 = dlg.m_flag1; data.group = dlg.m_group; data.flag3 = dlg.m_flag3; @@ -2257,19 +2261,21 @@ void CIsoView::HandleProperties(int n, int type) CBuilding dlg(this); char tmp[255]; - dlg.Init((LPCTSTR)data.house, (LPCTSTR)data.strength, (LPCTSTR)data.direction, (LPCTSTR)data.tag, - (LPCTSTR)data.flag1, (LPCTSTR)data.flag2, (LPCTSTR)data.energy, - (LPCTSTR)data.upgradecount, (LPCTSTR)data.spotlight, (LPCTSTR)data.upgrade1, (LPCTSTR)data.upgrade2, - (LPCTSTR)data.upgrade3, (LPCTSTR)data.flag3, (LPCTSTR)data.flag4); - dlg.m_type = data.type; + dlg.Init(data.basic.house, data.basic.strength, data.direction, data.tag, + data.flag1, data.flag2, data.energy, + data.upgradecount, data.spotlight, data.upgrade1, data.upgrade2, + data.upgrade3, data.flag3, data.flag4); + dlg.m_type = data.basic.type; int res = dlg.DoModal(); - if (res == IDCANCEL) return; + if (res == IDCANCEL) { + return; + } - data.strength = dlg.m_strength; + data.basic.strength = dlg.m_strength; data.tag = dlg.m_tag; data.direction = dlg.m_direction; - data.house = dlg.m_house; + data.basic.house = dlg.m_house; data.spotlight = dlg.m_spotlight; data.flag1 = dlg.m_flag1; data.flag2 = dlg.m_flag2; @@ -2300,17 +2306,17 @@ void CIsoView::HandleProperties(int n, int type) CAircraft dlg(this); char tmp[255]; - dlg.Init(data.house, data.strength, data.direction, data.action, + dlg.Init(data.basic.house, data.basic.strength, data.direction, data.action, data.tag, data.flag1, data.group, data.flag3, data.flag4); int res = dlg.DoModal(); if (res == IDCANCEL) return; data.action = dlg.m_action; - data.strength = dlg.m_strength; + data.basic.strength = dlg.m_strength; data.tag = dlg.m_tag; data.direction = dlg.m_direction; - data.house = dlg.m_house; + data.basic.house = dlg.m_house; data.flag1 = dlg.m_flag1; data.group = dlg.m_group; data.flag3 = dlg.m_flag3; @@ -2333,17 +2339,19 @@ void CIsoView::HandleProperties(int n, int type) CUnit dlg(this); char tmp[255]; - dlg.Init(data.house, data.strength, data.direction, data.action, + dlg.Init(data.basic.house, data.basic.strength, data.direction, data.action, data.tag, data.flag1, data.group, data.flag3, data.flag4, data.flag5, data.flag6); int res = dlg.DoModal(); - if (res == IDCANCEL) return; + if (res == IDCANCEL) { + return; + } data.action = dlg.m_action; - data.strength = dlg.m_strength; + data.basic.strength = dlg.m_strength; data.tag = dlg.m_tag; data.direction = dlg.m_direction; - data.house = dlg.m_house; + data.basic.house = dlg.m_house; data.flag1 = dlg.m_flag1; data.group = dlg.m_group; data.flag3 = dlg.m_flag3; @@ -2994,8 +3002,8 @@ void CIsoView::OnLButtonUp(UINT nFlags, CPoint point) { INFANTRY infantry; Map->GetInfantryData(m_id, &infantry); - infantry.x = strX; - infantry.y = strY; + infantry.basic.x = strX; + infantry.basic.y = strY; infantry.pos = "-1"; if ((nFlags != MK_SHIFT)) { @@ -3010,8 +3018,8 @@ void CIsoView::OnLButtonUp(UINT nFlags, CPoint point) { STRUCTURE structure; Map->GetStructureData(m_id, &structure); - structure.x = strX; - structure.y = strY; + structure.basic.x = strX; + structure.basic.y = strY; if ((nFlags != MK_SHIFT)) { Map->DeleteStructure(m_id); @@ -3025,8 +3033,8 @@ void CIsoView::OnLButtonUp(UINT nFlags, CPoint point) { AIRCRAFT aircraft; Map->GetAircraftData(m_id, &aircraft); - aircraft.x = strX; - aircraft.y = strY; + aircraft.basic.x = strX; + aircraft.basic.y = strY; if ((nFlags != MK_SHIFT)) { @@ -3041,8 +3049,8 @@ void CIsoView::OnLButtonUp(UINT nFlags, CPoint point) { UNIT unit; Map->GetUnitData(m_id, &unit); - unit.x = strX; - unit.y = strY; + unit.basic.x = strX; + unit.basic.y = strY; if (!(nFlags == MK_SHIFT)) { Map->DeleteUnit(m_id); @@ -4050,10 +4058,13 @@ void CIsoView::UpdateStatusBar(int x, int y) CString statusbar;//=TranslateStringACP("Ready"); FIELDDATA m = *Map->GetFielddataAt(x + y * Map->GetIsoSize()); - if (m.wGround == 0xFFFF) m.wGround = 0; + if (m.wGround == 0xFFFF) { + m.wGround = 0; + } if (m.wGround < (*tiledata_count) && m.bSubTile < (*tiledata)[m.wGround].wTileCount) { - statusbar = "Terrain type: 0x"; + statusbar = GetLanguageStringACP("TerrainStatus"); + statusbar += " 0x"; char c[50]; itoa((*tiledata)[m.wGround].tiles[m.bSubTile].bTerrainType, c, 16); statusbar += c; @@ -4086,56 +4097,64 @@ void CIsoView::UpdateStatusBar(int x, int y) statusbar += ov; } - STDOBJECTDATA sod; - sod.type = ""; + auto type = TechnoType::None; + TECHNODATA techno; - int n = Map->GetStructureAt(x + y * Map->GetIsoSize()); - int on = -1; - if (n >= 0) { - - Map->GetStdStructureData(n, &sod); + int objId = -1; + if (int n = Map->GetStructureAt(x + y * Map->GetIsoSize()); n >= 0) { + type = TechnoType::Building; statusbar = GetLanguageStringACP("StructStatus"); - on = n; + objId = n; } - n = Map->GetUnitAt(x + y * Map->GetIsoSize()); - if (n >= 0) { - - Map->GetStdUnitData(n, &sod); + if (int n = Map->GetUnitAt(x + y * Map->GetIsoSize()); n >= 0) { + type = TechnoType::Unit; statusbar = GetLanguageStringACP("UnitStatus"); - on = n; + objId = n; } - n = Map->GetAirAt(x + y * Map->GetIsoSize()); - if (n >= 0) { - - Map->GetStdAircraftData(n, &sod); + if (int n = Map->GetAirAt(x + y * Map->GetIsoSize()); n >= 0) { + type = TechnoType::Aircraft; statusbar = GetLanguageStringACP("AirStatus"); - on = n; + objId = n; } - n = Map->GetInfantryAt(x + y * Map->GetIsoSize()); - if (n >= 0) { - Map->GetStdInfantryData(n, &sod); + if (int n = Map->GetInfantryAt(x + y * Map->GetIsoSize()); n >= 0) { + type = TechnoType::Infantry; + INFANTRY inf; + Map->GetInfantryData(n, &inf); + techno = inf; statusbar = GetLanguageStringACP("InfStatus"); - on = n; + objId = n; } - if (sod.type.GetLength() > 0) { + if (objId >= 0 && type != TechnoType::Infantry) { + auto const [_, data] = Map->GetNthDataOfTechno(objId, type); + Map->ParseTechnoData(data, type, techno); + } + + if (techno.basic.type.GetLength() > 0) { char c[50]; - itoa(on, c, 10); + itoa(objId, c, 10); statusbar += "ID "; statusbar += c; statusbar += ", "; - statusbar += TranslateStringACP(Map->GetUnitName(sod.type)); + statusbar += TranslateStringACP(Map->GetUnitName(techno.basic.type)); statusbar += " ("; - statusbar += TranslateHouse(sod.house, TRUE); + statusbar += TranslateHouse(techno.basic.house, TRUE); statusbar += ", "; - statusbar += sod.type; + statusbar += techno.basic.type; statusbar += ")"; + + if (techno.tag != "None" && !techno.tag.IsEmpty()) { + statusbar += ", Tag: "; + statusbar += techno.tag; + statusbar += ' '; + statusbar += GetParam(Map->GetIniFile().GetString("Tags", techno.tag), 1); + } } /* @@ -4163,9 +4182,7 @@ void CIsoView::UpdateStatusBar(int x, int y) itoa(td.bMapData2[0],c,10); statusbar+=c;*/ - - n = Map->GetCelltagAt(x + y * Map->GetIsoSize()); - if (n >= 0) { + if (int n = Map->GetCelltagAt(x + y * Map->GetIsoSize()); n >= 0) { CString type; CString name; DWORD pos; @@ -4187,11 +4204,13 @@ void CIsoView::UpdateStatusBar(int x, int y) statusbar = GetLanguageStringACP("TilePlaceStatus"); } - if (AD.mode == ACTIONMODE_COPY) + if (AD.mode == ACTIONMODE_COPY) { statusbar = GetLanguageStringACP("CopyHelp"); + } - if (statusbar.GetLength() > 0) + if (statusbar.GetLength() > 0) { SetError(statusbar); + } } @@ -4919,7 +4938,7 @@ DWORD CIsoView::PlaceCurrentObjectAt(int x, int y) STRUCTURE structure; auto const id = Map->GetStructureData(t, &structure); Map->DeleteStructure(t); - structure.house = AD.data_s; + structure.basic.house = AD.data_s; Map->AddStructure(&structure, nullptr, nullptr, 0, std::move(id)); bchanged = TRUE; } @@ -4928,7 +4947,7 @@ DWORD CIsoView::PlaceCurrentObjectAt(int x, int y) UNIT unit; auto const id = Map->GetUnitData(t, &unit); Map->DeleteUnit(t); - unit.house = AD.data_s; + unit.basic.house = AD.data_s; Map->AddUnit(&unit, nullptr, nullptr, 0, std::move(id)); bchanged = TRUE; } @@ -4937,7 +4956,7 @@ DWORD CIsoView::PlaceCurrentObjectAt(int x, int y) AIRCRAFT aircraft; auto const id = Map->GetAircraftData(t, &aircraft); Map->DeleteAircraft(t); - aircraft.house = AD.data_s; + aircraft.basic.house = AD.data_s; Map->AddAircraft(&aircraft, nullptr, nullptr, 0, std::move(id)); bchanged = TRUE; } @@ -4948,7 +4967,7 @@ DWORD CIsoView::PlaceCurrentObjectAt(int x, int y) INFANTRY infantry; Map->GetInfantryData(t, &infantry); Map->DeleteInfantry(t); - infantry.house = AD.data_s; + infantry.basic.house = AD.data_s; Map->AddInfantry(&infantry, t); bchanged = TRUE; } @@ -5898,10 +5917,10 @@ void CIsoView::DrawMap() UNIT obj; Map->GetUnitData(m.unit, &obj); - COLORREF c = GetColor(obj.house); + COLORREF c = GetColor(obj.basic.house); auto const facing = atoi(obj.direction) / 32; - auto const imageId = theApp.m_loading->GetArtID(obj.type); + auto const imageId = theApp.m_loading->GetArtID(obj.basic.type); CString lpPicFile = GetUnitPictureFilename(imageId, facing); #ifndef NOSURFACES @@ -5913,9 +5932,9 @@ void CIsoView::DrawMap() } if (p.pic == NULL || lpPicFile.GetLength() == 0) { - if (!missingimages[obj.type]) { + if (!missingimages[obj.basic.type]) { SetError("Loading graphics"); - theApp.m_loading->LoadUnitGraphic(obj.type); + theApp.m_loading->LoadUnitGraphic(obj.basic.type); lpPicFile = GetUnitPictureFilename(imageId, facing); if (!lpPicFile.IsEmpty()) { p = pics[lpPicFile]; @@ -5928,7 +5947,7 @@ void CIsoView::DrawMap() // TextOut(drawx+f_x/4,drawy+f_y/4, obj.type,c); m_texts_to_render.push_back({ obj.type, drawCoords.x + f_x / 4, drawCoords.y + f_y / 4, m_color_converter->GetColor(c) }); #endif - missingimages[obj.type] = TRUE; + missingimages[obj.basic.type] = TRUE; } } @@ -5951,10 +5970,10 @@ void CIsoView::DrawMap() AIRCRAFT obj; Map->GetAircraftData(m.aircraft, &obj); - COLORREF c = GetColor(obj.house); + COLORREF c = GetColor(obj.basic.house); auto const facing = atoi(obj.direction) / 32; - CString lpPicFile = GetUnitPictureFilename(theApp.m_loading->GetArtID(obj.type), facing); + CString lpPicFile = GetUnitPictureFilename(theApp.m_loading->GetArtID(obj.basic.type), facing); #ifndef NOSURFACES DrawCell(drawCoords.x, drawCoords.y, 1, 1, c); @@ -5965,10 +5984,10 @@ void CIsoView::DrawMap() } if (p.pic == NULL) { - if (!missingimages[obj.type]) { + if (!missingimages[obj.basic.type]) { SetError("Loading graphics"); - theApp.m_loading->LoadUnitGraphic(obj.type); - lpPicFile = GetUnitPictureFilename(theApp.m_loading->GetArtID(obj.type), facing); + theApp.m_loading->LoadUnitGraphic(obj.basic.type); + lpPicFile = GetUnitPictureFilename(theApp.m_loading->GetArtID(obj.basic.type), facing); if (!lpPicFile.IsEmpty()) { p = pics[lpPicFile]; } @@ -5980,7 +5999,7 @@ void CIsoView::DrawMap() //TextOut(drawx+f_x/4,drawy+f_y/4, obj.type,c); m_texts_to_render.push_back({ obj.type, drawCoords.x + f_x / 4, drawCoords.y + f_y / 4, m_color_converter->GetColor(c) }); #endif - missingimages[obj.type] = TRUE; + missingimages[obj.basic.type] = TRUE; } } @@ -6012,11 +6031,11 @@ void CIsoView::DrawMap() //errstream.flush(); - COLORREF c = GetColor(obj.house); + COLORREF c = GetColor(obj.basic.house); int dir = (7 - atoi(obj.direction) / 32) % 8; - auto const imageId = theApp.m_loading->GetArtID(obj.type); + auto const imageId = theApp.m_loading->GetArtID(obj.basic.type); CString lpPicFile = GetUnitPictureFilename(imageId, dir); #ifndef NOSURFACES DrawCell(drawCoords.x, drawCoords.y, 1, 1, c); @@ -6038,9 +6057,9 @@ void CIsoView::DrawMap() } if (p.pic == NULL) { - if (!missingimages[obj.type]) { + if (!missingimages[obj.basic.type]) { SetError("Loading graphics"); - theApp.m_loading->LoadUnitGraphic(obj.type); + theApp.m_loading->LoadUnitGraphic(obj.basic.type); lpPicFile = GetUnitPictureFilename(imageId, dir); if (!lpPicFile.IsEmpty()) { p = pics[lpPicFile]; @@ -6053,7 +6072,7 @@ void CIsoView::DrawMap() // TextOut(drawx+f_x/4,drawy+f_y/4, obj.type,c); m_texts_to_render.push_back({ obj.type, drawCoordsInf.x + f_x / 4, drawCoordsInf.y + f_y / 4, RGB(0,0,0) }); #endif - missingimages[obj.type] = TRUE; + missingimages[obj.basic.type] = TRUE; } } diff --git a/MissionEditor/MapData.cpp b/MissionEditor/MapData.cpp index dda9100..0a80c82 100644 --- a/MissionEditor/MapData.cpp +++ b/MissionEditor/MapData.cpp @@ -1468,21 +1468,9 @@ void CMapData::UpdateInfantry(BOOL bSave) int pos = x + y * GetIsoSize(); INFANTRY id; + ParseInfantryData(data, id); + id.deleted = 0; - id.house = GetParam(data, 0); - id.type = GetParam(data, 1); - id.strength = GetParam(data, 2); - id.y = GetParam(data, 3); - id.x = GetParam(data, 4); - id.pos = GetParam(data, 5); - id.action = GetParam(data, 6); - id.direction = GetParam(data, 7); - id.tag = GetParam(data, 8); - id.flag1 = GetParam(data, 9); - id.group = GetParam(data, 10); - id.flag3 = GetParam(data, 11); - id.flag4 = GetParam(data, 12); - id.flag5 = GetParam(data, 13); iv.push_back(id); @@ -1520,13 +1508,12 @@ void CMapData::UpdateInfantry(BOOL bSave) int count = 0; for (i = 0; i < iv.size(); i++) { - INFANTRY& id = iv[i]; - if (!id.deleted) { - INFANTRY& infantry = id; + const INFANTRY& infantry = iv[i]; + if (!infantry.deleted) { CString value; - value = infantry.house + "," + infantry.type + "," + infantry.strength + "," + infantry.y + - "," + infantry.x + "," + infantry.pos + "," + infantry.action + "," + infantry.direction + "," + + value = infantry.basic.house + "," + infantry.basic.type + "," + infantry.basic.strength + "," + infantry.basic.y + + "," + infantry.basic.x + "," + infantry.pos + "," + infantry.action + "," + infantry.direction + "," + infantry.tag + "," + infantry.flag1 + "," + infantry.group + "," + infantry.flag3 + "," + infantry.flag4 + "," + infantry.flag5; @@ -1868,8 +1855,8 @@ void CMapData::DeleteInfantry(DWORD dwIndex) m_infantry[dwIndex].deleted = 1; - int x = atoi(m_infantry[dwIndex].x); - int y = atoi(m_infantry[dwIndex].y); + int x = atoi(m_infantry[dwIndex].basic.x); + int y = atoi(m_infantry[dwIndex].basic.y); int pos = atoi(m_infantry[dwIndex].pos); if (pos > 0) { @@ -2080,47 +2067,17 @@ BOOL CMapData::AddWaypoint(CString id, DWORD dwPos) CString CMapData::GetStructureData(DWORD dwIndex, STRUCTURE* lpStructure) const { - auto const& section = m_mapfile.GetSection("Structures"); - if (dwIndex >= section.Size()) { + auto const [id, data] = GetNthDataOfTechno(dwIndex, TechnoType::Building); + if (!ParseStructureData(data, *lpStructure)) { return {}; } - - auto const& [id, data] = section.Nth(dwIndex); - - lpStructure->house = GetParam(data, 0); - lpStructure->type = GetParam(data, 1); - lpStructure->strength = GetParam(data, 2); - lpStructure->y = GetParam(data, 3); - lpStructure->x = GetParam(data, 4); - lpStructure->direction = GetParam(data, 5); - lpStructure->tag = GetParam(data, 6); - lpStructure->flag1 = GetParam(data, 7); - lpStructure->flag2 = GetParam(data, 8); - lpStructure->energy = GetParam(data, 9); - lpStructure->upgradecount = GetParam(data, 10); - lpStructure->spotlight = GetParam(data, 11); - lpStructure->upgrade1 = GetParam(data, 12); - lpStructure->upgrade2 = GetParam(data, 13); - lpStructure->upgrade3 = GetParam(data, 14); - lpStructure->flag3 = GetParam(data, 15); - lpStructure->flag4 = GetParam(data, 16); - return id; } void CMapData::GetStdStructureData(DWORD dwIndex, STDOBJECTDATA* lpStdStructure) const { - auto const& section = m_mapfile.GetSection("Structures"); - if (dwIndex >= section.Size()) { - return; - } - auto const& data = section.Nth(dwIndex).second; - - lpStdStructure->house = GetParam(data, 0); - lpStdStructure->type = GetParam(data, 1); - lpStdStructure->strength = GetParam(data, 2); - lpStdStructure->y = GetParam(data, 3); - lpStdStructure->x = GetParam(data, 4); + auto const [_, data] = GetNthDataOfTechno(dwIndex, TechnoType::Building); + ParseBasicTechnoData(data, *lpStdStructure); } BOOL CMapData::AddNode(NODE* lpNode, WORD dwPos) @@ -2169,7 +2126,7 @@ BOOL CMapData::AddInfantry(INFANTRY* lpInfantry, int suggestedIndex, LPCTSTR lpT INFANTRY infantry; if (lpInfantry != NULL) { infantry = *lpInfantry; - dwPos = atoi(infantry.x) + atoi(infantry.y) * Map->GetIsoSize(); + dwPos = atoi(infantry.basic.x) + atoi(infantry.basic.y) * Map->GetIsoSize(); // MW Bugfix: not checking if infantry.pos does already exist caused crashes with user scripts! if (GetInfantryAt(dwPos, atoi(infantry.pos)) >= 0) { @@ -2190,12 +2147,12 @@ BOOL CMapData::AddInfantry(INFANTRY* lpInfantry, int suggestedIndex, LPCTSTR lpT infantry.flag3 = "0"; infantry.flag4 = "1"; infantry.flag5 = "0"; - infantry.strength = "256"; - infantry.house = lpHouse; infantry.pos = "-1"; - infantry.type = lpType; - infantry.x = cx; - infantry.y = cy; + infantry.basic.strength = "256"; + infantry.basic.house = lpHouse; + infantry.basic.type = lpType; + infantry.basic.x = cx; + infantry.basic.y = cy; } @@ -2324,6 +2281,11 @@ BOOL CMapData::AddStructure(STRUCTURE* lpStructure, LPCTSTR lpType, LPCTSTR lpHo itoa(dwPos % Map->GetIsoSize(), cx, 10); itoa(dwPos / Map->GetIsoSize(), cy, 10); + structure.basic.strength = "256"; + structure.basic.house = lpHouse; + structure.basic.type = lpType; + structure.basic.x = cx; + structure.basic.y = cy; structure.tag = "None"; structure.direction = "0"; structure.flag1 = "1"; @@ -2336,11 +2298,6 @@ BOOL CMapData::AddStructure(STRUCTURE* lpStructure, LPCTSTR lpType, LPCTSTR lpHo structure.upgrade2 = "None"; structure.upgrade3 = "None"; structure.upgradecount = "0"; - structure.strength = "256"; - structure.house = lpHouse; - structure.type = lpType; - structure.x = cx; - structure.y = cy; } @@ -2353,8 +2310,8 @@ BOOL CMapData::AddStructure(STRUCTURE* lpStructure, LPCTSTR lpType, LPCTSTR lpHo } CString value; - value = structure.house + "," + structure.type + "," + structure.strength + "," + structure.y + - "," + structure.x + "," + structure.direction + "," + structure.tag + "," + structure.flag1 + "," + + value = structure.basic.house + "," + structure.basic.type + "," + structure.basic.strength + "," + structure.basic.y + + "," + structure.basic.x + "," + structure.direction + "," + structure.tag + "," + structure.flag1 + "," + structure.flag2 + "," + structure.energy + "," + structure.upgradecount + "," + structure.spotlight + "," + structure.upgrade1 + "," + structure.upgrade2 + "," + structure.upgrade3 + "," + structure.flag3 + "," + structure.flag4; @@ -2426,22 +2383,8 @@ INT CMapData::GetUnitTypeID(LPCTSTR lpType) void CMapData::GetStdInfantryData(DWORD dwIndex, STDOBJECTDATA* lpStdInfantry) const { - /*CString data=*m_mapfile.sections["Infantry"].GetValue(dwIndex); - - lpStdInfantry->house=GetParam(data, 0); - lpStdInfantry->type=GetParam(data, 1); - lpStdInfantry->strength=atoi(GetParam(data, 2)); - lpStdInfantry->y=GetParam(data, 3); - lpStdInfantry->x=atoi(GetParam(data, 4));*/ - - lpStdInfantry->house = m_infantry[dwIndex].house; - lpStdInfantry->type = m_infantry[dwIndex].type; - lpStdInfantry->strength = m_infantry[dwIndex].strength; - lpStdInfantry->y = m_infantry[dwIndex].y; - lpStdInfantry->x = m_infantry[dwIndex].x; - + *lpStdInfantry = m_infantry[dwIndex].basic; } - void CMapData::GetInfantryData(DWORD dwIndex, INFANTRY* lpInfantry) const { ASSERT(dwIndex < m_infantry.size()); @@ -2449,100 +2392,155 @@ void CMapData::GetInfantryData(DWORD dwIndex, INFANTRY* lpInfantry) const if (dwIndex >= m_infantry.size()) { return; } - - /*lpInfantry->house=m_infantry.house; - lpInfantry->type=m_infantry.; - lpInfantry->strength=m_infantry.; - lpInfantry->y=m_infantry.; - lpInfantry->x=m_infantry.; - lpInfantry->pos=m_infantry.; - lpInfantry->action=m_infantry.; - lpInfantry->direction=m_infantry.; - lpInfantry->tag=m_infantry.; - lpInfantry->flag1=m_infantry.; - lpInfantry->flag2=m_infantry.; - lpInfantry->flag3=m_infantry.; - lpInfantry->flag4=m_infantry.; - lpInfantry->flag5=m_infantry.;*/ *lpInfantry = m_infantry[dwIndex]; - - //memcpy(lpInfantry, &m_infantry[dwIndex], sizeof(INFANTRY)); - - //ASSERT(dwIndex>=0 && dwIndex=m_mapfile.sections["Infantry"].values.size()) return; - - CString data=*m_mapfile.sections["Infantry"].GetValue(dwIndex); - - lpInfantry->house=GetParam(data, 0); - lpInfantry->type=GetParam(data, 1); - lpInfantry->strength=GetParam(data, 2); - lpInfantry->y=GetParam(data, 3); - lpInfantry->x=GetParam(data, 4); - lpInfantry->pos=GetParam(data, 5); - lpInfantry->action=GetParam(data, 6); - lpInfantry->direction=GetParam(data, 7); - lpInfantry->tag=GetParam(data, 8); - lpInfantry->flag1=GetParam(data, 9); - lpInfantry->flag2=GetParam(data, 10); - lpInfantry->flag3=GetParam(data, 11); - lpInfantry->flag4=GetParam(data, 12); - lpInfantry->flag5=GetParam(data, 13);*/ - } - CString CMapData::GetUnitData(DWORD dwIndex, UNIT* lpUnit) const { - auto const& section = m_mapfile.GetSection("Units"); - if (dwIndex >= section.Size()) { + auto const [id, data] = GetNthDataOfTechno(dwIndex, TechnoType::Unit); + if (!ParseUnitData(data, *lpUnit)) { + return {}; + } + return id; +} +CString CMapData::GetAircraftData(DWORD dwIndex, AIRCRAFT* lpAircraft) const +{ + auto const [id, data] = GetNthDataOfTechno(dwIndex, TechnoType::Aircraft); + if (!ParseAircraftData(data, *lpAircraft)) { return {}; } - - auto const& [id, data] = section.Nth(dwIndex); - - lpUnit->house = GetParam(data, 0); - lpUnit->type = GetParam(data, 1); - lpUnit->strength = GetParam(data, 2); - lpUnit->y = GetParam(data, 3); - lpUnit->x = GetParam(data, 4); - lpUnit->direction = GetParam(data, 5); - lpUnit->action = GetParam(data, 6); - lpUnit->tag = GetParam(data, 7); - lpUnit->flag1 = GetParam(data, 8); - lpUnit->group = GetParam(data, 9); - lpUnit->flag3 = GetParam(data, 10); - lpUnit->flag4 = GetParam(data, 11); - lpUnit->flag5 = GetParam(data, 12); - lpUnit->flag6 = GetParam(data, 13); - return id; } -CString CMapData::GetAircraftData(DWORD dwIndex, AIRCRAFT* lpAircraft) const +bool CMapData::ParseInfantryData(const CString& rawText, INFANTRY& infantry) const { - auto const& section = m_mapfile.GetSection("Aircraft"); - if (dwIndex >= section.Size()) { + if (!ParseTechnoData(rawText, TechnoType::Infantry, infantry)) { + return false; + } + infantry.pos = GetParam(rawText, 5); + infantry.action = GetParam(rawText, 6); + infantry.flag1 = GetParam(rawText, 9); + infantry.group = GetParam(rawText, 10); + infantry.flag3 = GetParam(rawText, 11); + infantry.flag4 = GetParam(rawText, 12); + infantry.flag5 = GetParam(rawText, 13); + + return true; +} +bool CMapData::ParseUnitData(const CString& rawText, UNIT& unit) const +{ + if (!ParseTechnoData(rawText, TechnoType::Unit, unit)) { + return false; + } + unit.action = GetParam(rawText, 6); + unit.flag1 = GetParam(rawText, 8); + unit.group = GetParam(rawText, 9); + unit.flag3 = GetParam(rawText, 10); + unit.flag4 = GetParam(rawText, 11); + unit.flag5 = GetParam(rawText, 12); + unit.flag6 = GetParam(rawText, 13); + + return true; +} +bool CMapData::ParseAircraftData(const CString& rawText, AIRCRAFT& aircraft) const +{ + if (!ParseTechnoData(rawText, TechnoType::Aircraft, aircraft)) { + return false; + } + aircraft.action = GetParam(rawText, 6); + aircraft.flag1 = GetParam(rawText, 8); + aircraft.group = GetParam(rawText, 9); + aircraft.flag3 = GetParam(rawText, 10); + aircraft.flag4 = GetParam(rawText, 11); + + return true; +} +bool CMapData::ParseStructureData(const CString& rawText, STRUCTURE& structure) const +{ + if (!ParseTechnoData(rawText, TechnoType::Building, structure)) { + return false; + } + structure.flag1 = GetParam(rawText, 7); + structure.flag2 = GetParam(rawText, 8); + structure.energy = GetParam(rawText, 9); + structure.upgradecount = GetParam(rawText, 10); + structure.spotlight = GetParam(rawText, 11); + structure.upgrade1 = GetParam(rawText, 12); + structure.upgrade2 = GetParam(rawText, 13); + structure.upgrade3 = GetParam(rawText, 14); + structure.flag3 = GetParam(rawText, 15); + structure.flag4 = GetParam(rawText, 16); + + return true; +} + +std::pair CMapData::GetNthDataOfTechno(const size_t index, const TechnoType type) const +{ + CString sectionID; + switch (type) + { + case TechnoType::Building: + sectionID = "Structures"; + break; + case TechnoType::Unit: + sectionID = "Units"; + break; + case TechnoType::Aircraft: + sectionID = "Aircraft"; + break; + case TechnoType::Infantry: + throw std::runtime_error("infantry raw data does not support retrieving in this way"); + break; + default: + break; + } + auto const& section = m_mapfile.GetSection(sectionID); + if (index >= section.Size()) { return {}; } + return section.Nth(index); +} - auto const& [id, data] = section.Nth(dwIndex); +bool CMapData::ParseBasicTechnoData(const CString& rawText, STDOBJECTDATA& data) const +{ + if (rawText.IsEmpty()) { + return false; + } + data.house = GetParam(rawText, 0); + data.type = GetParam(rawText, 1); + data.strength = GetParam(rawText, 2); + data.y = GetParam(rawText, 3); + data.x = GetParam(rawText, 4); + return true; +} - lpAircraft->house = GetParam(data, 0); - lpAircraft->type = GetParam(data, 1); - lpAircraft->strength = GetParam(data, 2); - lpAircraft->y = GetParam(data, 3); - lpAircraft->x = GetParam(data, 4); - lpAircraft->direction = GetParam(data, 5); - lpAircraft->action = GetParam(data, 6); - lpAircraft->tag = GetParam(data, 7); - lpAircraft->flag1 = GetParam(data, 8); - lpAircraft->group = GetParam(data, 9); - lpAircraft->flag3 = GetParam(data, 10); - lpAircraft->flag4 = GetParam(data, 11); +bool CMapData::ParseTechnoData(const CString& rawText, const TechnoType type, TECHNODATA& data) const +{ + if (!ParseBasicTechnoData(rawText, data.basic)) { + return false; + } + switch (type) + { + case TechnoType::Building: + data.direction = GetParam(rawText, 5); + data.tag = GetParam(rawText, 6); + break; + case TechnoType::Infantry: + data.direction = GetParam(rawText, 7); + data.tag = GetParam(rawText, 8); + break; + case TechnoType::Unit: + data.direction = GetParam(rawText, 5); + data.tag = GetParam(rawText, 7); + break; + case TechnoType::Aircraft: + data.direction = GetParam(rawText, 5); + data.tag = GetParam(rawText, 7); + break; + default: + break; + } - return id; + return true; } BOOL CMapData::AddCelltag(LPCTSTR lpTag, DWORD dwPos) @@ -2596,14 +2594,14 @@ BOOL CMapData::AddAircraft(AIRCRAFT* lpAircraft, LPCTSTR lpType, LPCTSTR lpHouse itoa(dwPos % GetIsoSize(), sx, 10); itoa(dwPos / GetIsoSize(), sy, 10); - aircraft.type = lpType; - aircraft.house = lpHouse; + aircraft.basic.type = lpType; + aircraft.basic.house = lpHouse; + aircraft.basic.strength = "256"; + aircraft.basic.x = sx; + aircraft.basic.y = sy; aircraft.action = "Guard"; aircraft.tag = "None"; aircraft.direction = "0"; - aircraft.strength = "256"; - aircraft.x = sx; - aircraft.y = sy; aircraft.flag1 = "0"; aircraft.group = "-1"; aircraft.flag3 = "1"; @@ -2617,8 +2615,8 @@ BOOL CMapData::AddAircraft(AIRCRAFT* lpAircraft, LPCTSTR lpType, LPCTSTR lpHouse } CString value; - value = aircraft.house + "," + aircraft.type + "," + aircraft.strength + "," + aircraft.y + "," + - aircraft.x + "," + aircraft.direction + "," + aircraft.action + "," + aircraft.tag + "," + value = aircraft.basic.house + "," + aircraft.basic.type + "," + aircraft.basic.strength + "," + aircraft.basic.y + "," + + aircraft.basic.x + "," + aircraft.direction + "," + aircraft.action + "," + aircraft.tag + "," + aircraft.flag1 + "," + aircraft.group + "," + aircraft.flag3 + "," + aircraft.flag4; m_mapfile.AddSection("Aircraft").InsertOrAssign(id, value); @@ -2641,14 +2639,14 @@ BOOL CMapData::AddUnit(UNIT* lpUnit, LPCTSTR lpType, LPCTSTR lpHouse, DWORD dwPo itoa(dwPos % GetIsoSize(), sx, 10); itoa(dwPos / GetIsoSize(), sy, 10); - unit.type = lpType; - unit.house = lpHouse; + unit.basic.type = lpType; + unit.basic.house = lpHouse; + unit.basic.strength = "256"; + unit.basic.x = sx; + unit.basic.y = sy; unit.action = "Guard"; unit.tag = "None"; unit.direction = "0"; - unit.strength = "256"; - unit.x = sx; - unit.y = sy; unit.flag1 = "0"; unit.group = "-1"; unit.flag3 = "0"; @@ -2665,8 +2663,8 @@ BOOL CMapData::AddUnit(UNIT* lpUnit, LPCTSTR lpType, LPCTSTR lpHouse, DWORD dwPo } CString value; - value = unit.house + "," + unit.type + "," + unit.strength + "," + unit.y + "," + - unit.x + "," + unit.direction + "," + unit.action + "," + unit.tag + "," + value = unit.basic.house + "," + unit.basic.type + "," + unit.basic.strength + "," + unit.basic.y + "," + + unit.basic.x + "," + unit.direction + "," + unit.action + "," + unit.tag + "," + unit.flag1 + "," + unit.group + "," + unit.flag3 + "," + unit.flag4 + "," + unit.flag5 + "," + unit.flag6; m_mapfile.AddSection("Units").InsertOrAssign(id, value); @@ -2848,34 +2846,13 @@ void CMapData::GetWaypointData(DWORD dwId, CString* lpID, DWORD* lpdwPos) const void CMapData::GetStdAircraftData(DWORD dwIndex, STDOBJECTDATA* lpStdAircraft) const { - auto const& section = m_mapfile.GetSection("Aircraft"); - if (dwIndex >= section.Size()) { - return; - } - - auto const& data = section.Nth(dwIndex).second; - - lpStdAircraft->house = GetParam(data, 0); - lpStdAircraft->type = GetParam(data, 1); - lpStdAircraft->strength.Format("%d", atoi(GetParam(data, 2))); - lpStdAircraft->y = GetParam(data, 3); - lpStdAircraft->x.Format("%d", atoi(GetParam(data, 4))); + auto const [_, data] = GetNthDataOfTechno(dwIndex, TechnoType::Aircraft); + ParseBasicTechnoData(data, *lpStdAircraft); } - void CMapData::GetStdUnitData(DWORD dwIndex, STDOBJECTDATA* lpStdUnit) const { - auto const& section = m_mapfile.GetSection("Units"); - if (dwIndex >= section.Size()) { - return; - } - - auto const& data = section.Nth(dwIndex).second; - - lpStdUnit->house = GetParam(data, 0); - lpStdUnit->type = GetParam(data, 1); - lpStdUnit->strength.Format("%d", atoi(GetParam(data, 2))); - lpStdUnit->y = GetParam(data, 3); - lpStdUnit->x.Format("%d", atoi(GetParam(data, 4))); + auto const [_, data] = GetNthDataOfTechno(dwIndex, TechnoType::Unit); + ParseBasicTechnoData(data, *lpStdUnit); } DWORD CMapData::GetInfantryCount() const @@ -6092,52 +6069,50 @@ void CMapData::ResizeMap(int iLeft, int iTop, DWORD dwNewWidth, DWORD dwNewHeigh int ct_count = GetCelltagCount(); DWORD* ct_pos = new(DWORD[GetCelltagCount()]); - int i; - // Now copy the objects into above arrays and delete them from map - for (i = 0; i < inf_count; i++) { + for (int i = 0; i < inf_count; i++) { INFANTRY obj; GetInfantryData(i, &obj); inf[i] = obj; } - for (i = inf_count - 1; i >= 0; i--) + for (int i = inf_count - 1; i >= 0; i--) DeleteInfantry(i); - for (i = 0; i < air_count; i++) { + for (int i = 0; i < air_count; i++) { AIRCRAFT obj; GetAircraftData(i, &obj); air[i] = obj; } - for (i = air_count - 1; i >= 0; i--) + for (int i = air_count - 1; i >= 0; i--) DeleteAircraft(i); - for (i = 0; i < str_count; i++) { + for (int i = 0; i < str_count; i++) { STRUCTURE obj; GetStructureData(i, &obj); str[i] = obj; } - for (i = str_count - 1; i >= 0; i--) + for (int i = str_count - 1; i >= 0; i--) DeleteStructure(i); - for (i = 0; i < unit_count; i++) { + for (int i = 0; i < unit_count; i++) { UNIT obj; GetUnitData(i, &obj); unit[i] = obj; } - for (i = unit_count - 1; i >= 0; i--) + for (int i = unit_count - 1; i >= 0; i--) DeleteUnit(i); - for (i = 0; i < terrain_count; i++) { + for (int i = 0; i < terrain_count; i++) { terrain[i] = m_terrain[i]; } - for (i = 0; i < terrain_count; i++) + for (int i = 0; i < terrain_count; i++) DeleteTerrain(i); - for (i = 0; i < wp_count; i++) { + for (int i = 0; i < wp_count; i++) { DWORD pos; CString id; @@ -6150,7 +6125,7 @@ void CMapData::ResizeMap(int iLeft, int iTop, DWORD dwNewWidth, DWORD dwNewHeigh // for(i=0;i bool { + return x >= 0 && y >= 0 && x < isoSize && y < isoSize; + }; // copy tiles now - int e; - for (i = 0; i < os; i++) { - for (e = 0; e < os; e++) { + for (int i = 0; i < os; i++) { + for (int e = 0; e < os; e++) { int x, y; x = i + x_move; y = e + y_move; - if (x < 0 || y < 0 || x >= m_IsoSize || y >= m_IsoSize) continue; + if (!isInMap(x, y)) { + continue; + } FIELDDATA& fdd = fielddata[x + y * m_IsoSize]; FIELDDATA& fdo = old_fd[i + e * os]; @@ -6296,8 +6275,20 @@ void CMapData::ResizeMap(int iLeft, int iTop, DWORD dwNewWidth, DWORD dwNewHeigh //m_noAutoObjectUpdate=TRUE; // deactivate Update*()... faster + auto updateCoords = [isInMap](STDOBJECTDATA& data, const int x_move, const int y_move) -> bool { + const int x = atoi(data.x) + x_move; + const int y = atoi(data.y) + y_move; + + if (!isInMap(x, y)) { + return false; + } + data.x.Format("%d", x); + data.y.Format("%d", y); + return true; + }; + int count = inf_count; // this temp variable is *needed* (infinite loop)!!! - for (i = 0; i < count; i++) { + for (int i = 0; i < count; i++) { if (inf[i].deleted) { dlg->SetPosition(i + curcount); dlg->UpdateWindow(); @@ -6308,15 +6299,7 @@ void CMapData::ResizeMap(int iLeft, int iTop, DWORD dwNewWidth, DWORD dwNewHeigh INFANTRY obj; obj = inf[i]; - char c[50]; - obj.x = itoa(atoi(obj.x) + x_move, c, 10); - obj.y = itoa(atoi(obj.y) + y_move, c, 10); - - int x = atoi(obj.x); - int y = atoi(obj.y); - - - if (x < 0 || y < 0 || x >= m_IsoSize || y >= m_IsoSize) { + if (!updateCoords(obj.basic, x_move, y_move)) { continue; } @@ -6330,21 +6313,15 @@ void CMapData::ResizeMap(int iLeft, int iTop, DWORD dwNewWidth, DWORD dwNewHeigh curcount += count; count = air_count; - for (i = 0; i < count; i++) { + for (int i = 0; i < count; i++) { // if(air[i].deleted) continue; AIRCRAFT obj; obj = air[i]; - char c[50]; - obj.x = itoa(atoi(obj.x) + x_move, c, 10); - obj.y = itoa(atoi(obj.y) + y_move, c, 10); - - int x = atoi(obj.x); - int y = atoi(obj.y); - - - if (x < 0 || y < 0 || x >= m_IsoSize || y >= m_IsoSize) continue; + if (!updateCoords(obj.basic, x_move, y_move)) { + continue; + } AddAircraft(&obj); @@ -6357,21 +6334,15 @@ void CMapData::ResizeMap(int iLeft, int iTop, DWORD dwNewWidth, DWORD dwNewHeigh curcount += count; count = str_count; - for (i = 0; i < count; i++) { + for (int i = 0; i < count; i++) { // if(str[i].deleted) continue; STRUCTURE obj; obj = str[i]; - char c[50]; - obj.x = itoa(atoi(obj.x) + x_move, c, 10); - obj.y = itoa(atoi(obj.y) + y_move, c, 10); - - int x = atoi(obj.x); - int y = atoi(obj.y); - - - if (x < 0 || y < 0 || x >= m_IsoSize || y >= m_IsoSize) continue; + if (!updateCoords(obj.basic, x_move, y_move)) { + continue; + } AddStructure(&obj); @@ -6384,21 +6355,15 @@ void CMapData::ResizeMap(int iLeft, int iTop, DWORD dwNewWidth, DWORD dwNewHeigh curcount += count; count = unit_count; - for (i = 0; i < count; i++) { + for (int i = 0; i < count; i++) { // if(units[i].deleted) continue; UNIT obj; obj = unit[i]; - char c[50]; - obj.x = itoa(atoi(obj.x) + x_move, c, 10); - obj.y = itoa(atoi(obj.y) + y_move, c, 10); - - int x = atoi(obj.x); - int y = atoi(obj.y); - - - if (x < 0 || y < 0 || x >= m_IsoSize || y >= m_IsoSize) continue; + if (!updateCoords(obj.basic, x_move, y_move)) { + continue; + } AddUnit(&obj); @@ -6411,7 +6376,7 @@ void CMapData::ResizeMap(int iLeft, int iTop, DWORD dwNewWidth, DWORD dwNewHeigh curcount += count; count = terrain_count; - for (i = 0; i < count; i++) { + for (int i = 0; i < count; i++) { if (terrain[i].deleted) { dlg->SetPosition(i + curcount); dlg->UpdateWindow(); @@ -6429,7 +6394,9 @@ void CMapData::ResizeMap(int iLeft, int iTop, DWORD dwNewWidth, DWORD dwNewHeigh y = y + y_move; - if (x < 0 || y < 0 || x >= m_IsoSize || y >= m_IsoSize) continue; + if (!isInMap(x, y)) { + continue; + } AddTerrain(obj, x + y * m_IsoSize); @@ -6443,7 +6410,7 @@ void CMapData::ResizeMap(int iLeft, int iTop, DWORD dwNewWidth, DWORD dwNewHeigh curcount += count; count = wp_count; - for (i = 0; i < count; i++) { + for (int i = 0; i < count; i++) { DWORD pos; CString id; @@ -6453,7 +6420,9 @@ void CMapData::ResizeMap(int iLeft, int iTop, DWORD dwNewWidth, DWORD dwNewHeigh int x = pos % os + x_move; int y = pos / os + y_move; - if (x < 0 || y < 0 || x >= m_IsoSize || y >= m_IsoSize) continue; + if (!isInMap(x, y)) { + continue; + } AddWaypoint(id, x + y * m_IsoSize); @@ -6466,14 +6435,16 @@ void CMapData::ResizeMap(int iLeft, int iTop, DWORD dwNewWidth, DWORD dwNewHeigh curcount += count; - for (i = 0; i < ct_count; i++) { + for (int i = 0; i < ct_count; i++) { DWORD pos = ct_pos[i]; CString tag = ct_tag[i]; int x = pos % os + x_move; int y = pos / os + y_move; - if (x < 0 || y < 0 || x >= m_IsoSize || y >= m_IsoSize) continue; + if (!isInMap(x, y)) { + continue; + } AddCelltag(tag, x + y * m_IsoSize); @@ -6505,8 +6476,8 @@ void CMapData::ResizeMap(int iLeft, int iTop, DWORD dwNewWidth, DWORD dwNewHeigh errstream.flush(); const bool mp = IsMultiplayer(); - for (i = 0; i < m_IsoSize; i++) { - for (e = 0; e < m_IsoSize; e++) { + for (int i = 0; i < m_IsoSize; i++) { + for (int e = 0; e < m_IsoSize; e++) { Mini_UpdatePos(i, e, mp); count++; @@ -6530,8 +6501,6 @@ void CMapData::ResizeMap(int iLeft, int iTop, DWORD dwNewWidth, DWORD dwNewHeigh if (ct_pos) delete[] ct_pos; dlg->DestroyWindow(); - - } /* @@ -6594,7 +6563,7 @@ BOOL CMapData::IsYRMap() continue; } - if (g_data["YRInfantry"].Exists(inf.type)) { + if (g_data["YRInfantry"].Exists(inf.basic.type)) { return TRUE; } } @@ -6608,7 +6577,7 @@ BOOL CMapData::IsYRMap() continue; } - if (g_data["YRBuildings"].Exists(str.type)) { + if (g_data["YRBuildings"].Exists(str.basic.type)) { return TRUE; } } @@ -6622,7 +6591,7 @@ BOOL CMapData::IsYRMap() continue; } - if (g_data["YRUnits"].Exists(unit.type)) { + if (g_data["YRUnits"].Exists(unit.basic.type)) { return TRUE; } } @@ -6636,7 +6605,7 @@ BOOL CMapData::IsYRMap() continue; } - if (g_data["YRAircraft"].Exists(air.type)) { + if (g_data["YRAircraft"].Exists(air.basic.type)) { return TRUE; } } @@ -6906,8 +6875,8 @@ BOOL CMapData::GetInfantryINIData(int index, CString* lpINI) INFANTRY& infantry = m_infantry[index]; CString value; - value = infantry.house + "," + infantry.type + "," + infantry.strength + "," + infantry.y + - "," + infantry.x + "," + infantry.pos + "," + infantry.action + "," + infantry.direction + "," + + value = infantry.basic.house + "," + infantry.basic.type + "," + infantry.basic.strength + "," + infantry.basic.y + + "," + infantry.basic.x + "," + infantry.pos + "," + infantry.action + "," + infantry.direction + "," + infantry.tag + "," + infantry.flag1 + "," + infantry.group + "," + infantry.flag3 + "," + infantry.flag4 + "," + infantry.flag5; diff --git a/MissionEditor/MapData.h b/MissionEditor/MapData.h index fec8422..92edb4e 100644 --- a/MissionEditor/MapData.h +++ b/MissionEditor/MapData.h @@ -239,8 +239,7 @@ public: DWORD GetStructureCount() const; DWORD GetUnitCount() const; DWORD GetInfantryCount() const; - void GetStdUnitData(DWORD dwIndex, STDOBJECTDATA* lpStdUnit) const; - void GetStdAircraftData(DWORD dwIndex, STDOBJECTDATA* lpStdAircraft) const; + void GetNthWaypointData(DWORD dwIdx, CString* lpID, DWORD* lpdwPos) const; void GetWaypointData(DWORD dwId, CString* lpID, DWORD* lpdwPos) const; BOOL IsGroundObjectAt(DWORD dwPos) const; @@ -251,16 +250,27 @@ public: BOOL AddAircraft(AIRCRAFT* lpAircraft, LPCTSTR lpType = NULL, LPCTSTR lpHouse = NULL, DWORD dwPos = 0, CString suggestedID = ""); void GetCelltagData(DWORD dwIndex, CString* lpTag, DWORD* lpdwPos) const; BOOL AddCelltag(LPCTSTR lpTag, DWORD dwPos); + + std::pair GetNthDataOfTechno(const size_t index, const TechnoType type) const; + bool ParseBasicTechnoData(const CString& rawText, STDOBJECTDATA& data) const; + bool ParseTechnoData(const CString& rawText, const TechnoType type, TECHNODATA& data) const; CString GetAircraftData(DWORD dwIndex, AIRCRAFT* lpAircraft) const; CString GetUnitData(DWORD dwIndex, UNIT* lpUnit) const; + bool ParseInfantryData(const CString& rawText, INFANTRY& infantry) const; + bool ParseUnitData(const CString& rawText, UNIT& unit) const; + bool ParseAircraftData(const CString& rawText, AIRCRAFT& aircraft) const; + bool ParseStructureData(const CString& rawText, STRUCTURE& structure) const; void GetInfantryData(DWORD dwIndex, INFANTRY* lpInfantry) const; void GetStdInfantryData(DWORD dwIndex, STDOBJECTDATA* lpStdInfantry) const; + void GetStdUnitData(DWORD dwIndex, STDOBJECTDATA* lpStdUnit) const; + void GetStdAircraftData(DWORD dwIndex, STDOBJECTDATA* lpStdAircraft) const; + void GetStdStructureData(DWORD dwIndex, STDOBJECTDATA* lpStdStructure) const; + INT GetUnitTypeID(LPCTSTR lpType); void InitializeUnitTypes(); BOOL AddStructure(STRUCTURE* lpStructure, LPCTSTR lpType = NULL, LPCTSTR lpHouse = NULL, DWORD dwPos = 0, CString suggestedID = ""); BOOL AddInfantry(INFANTRY* lpInfantry, int suggestedIndex = -1, LPCTSTR lpType = NULL, LPCTSTR lpHouse = NULL, DWORD dwPos = 0); BOOL AddNode(NODE* lpNode, WORD dwPos); - void GetStdStructureData(DWORD dwIndex, STDOBJECTDATA* lpStdStructure) const; CString GetStructureData(DWORD dwIndex, STRUCTURE* lpStructure) const; BOOL AddWaypoint(CString lpID, DWORD dwPos); diff --git a/MissionEditor/Structs.h b/MissionEditor/Structs.h index 5644d33..2ccc1bd 100644 --- a/MissionEditor/Structs.h +++ b/MissionEditor/Structs.h @@ -45,6 +45,14 @@ enum class MouseActionType : unsigned { AddSmudge = 8, }; +enum class TechnoType : int { + Building, + Unit, + Infantry, + Aircraft, + None = -1, +}; + enum class TheaterChar : char { T = 'T', @@ -435,19 +443,19 @@ struct STDOBJECTDATA CString x; // 5 }; +struct TECHNODATA +{ + STDOBJECTDATA basic; + CString direction; + CString tag; +}; + /* STRUCTURE Data for a structure */ -struct STRUCTURE { - CString house; // 1 - CString type; // 2 - CString strength; // 3 - CString y; // 4 - CString x; // 5 - CString direction; // 6 - CString tag; // 7 +struct STRUCTURE: TECHNODATA { CString flag1; // 8 CString flag2; // 9 CString energy; // 10 @@ -481,16 +489,9 @@ struct INFANTRY{}; Data for an infantry unit */ -struct INFANTRY { - CString house; // 1 - CString type; // 2 - CString strength; // 3 - CString y; // 4 - CString x; // 5 +struct INFANTRY : TECHNODATA { CString pos; // 6 CString action; // 7 - CString direction; // 8 - CString tag; // 9 CString flag1; // 10 CString group; // 11 CString flag3; // 12 @@ -499,15 +500,8 @@ struct INFANTRY { unsigned deleted : 1; }; -struct UNIT { - CString house; // 1 - CString type; // 2 - CString strength; // 3 - CString y; // 4 - CString x; // 5 - CString direction; // 6 +struct UNIT : TECHNODATA { CString action; // 7 - CString tag; // 8 CString flag1; // 9 CString group; // 10 CString flag3; // 11 @@ -517,17 +511,8 @@ struct UNIT { unsigned deleted : 1; }; - - -struct AIRCRAFT { - CString house; // 1 - CString type; // 2 - CString strength; // 3 - CString y; // 4 - CString x; // 5 - CString direction; // 6 +struct AIRCRAFT : TECHNODATA { CString action; // 7 - CString tag; // 8 CString flag1; // 9 CString group; // 10 CString flag3; // 11 diff --git a/MissionEditor/UserScriptsDlg.cpp b/MissionEditor/UserScriptsDlg.cpp index d4b4bc9..f5b6ac3 100644 --- a/MissionEditor/UserScriptsDlg.cpp +++ b/MissionEditor/UserScriptsDlg.cpp @@ -2335,22 +2335,11 @@ void CUserScriptsDlg::OnOK() CString data = params[0]; INFANTRY id; + auto const parsed = Map->ParseInfantryData(data, id); + ASSERT(parsed); + id.deleted = 0; - id.house = GetParam(data, 0); - id.type = GetParam(data, 1); - id.strength = GetParam(data, 2); - id.y = GetParam(data, 3); - id.x = GetParam(data, 4); - //id.pos=GetParam(data, 5); id.pos = "-1"; // ignore pos values! - id.action = GetParam(data, 6); - id.direction = GetParam(data, 7); - id.tag = GetParam(data, 8); - id.flag1 = GetParam(data, 9); - id.group = GetParam(data, 10); - id.flag3 = GetParam(data, 11); - id.flag4 = GetParam(data, 12); - id.flag5 = GetParam(data, 13); if (Map->AddInfantry(&id, lastInfantryDeleted, NULL, NULL, NULL) == FALSE) { report += "AddInfantry failed\r\n"; @@ -2388,22 +2377,10 @@ void CUserScriptsDlg::OnOK() CString data = params[0]; UNIT unit; - unit.house = GetParam(data, 0); - unit.type = GetParam(data, 1); - unit.strength = GetParam(data, 2); - unit.y = GetParam(data, 3); - unit.x = GetParam(data, 4); - unit.direction = GetParam(data, 5); - unit.action = GetParam(data, 6); - unit.tag = GetParam(data, 7); - unit.flag1 = GetParam(data, 8); - unit.group = GetParam(data, 9); - unit.flag3 = GetParam(data, 10); - unit.flag4 = GetParam(data, 11); - unit.flag5 = GetParam(data, 12); - unit.flag6 = GetParam(data, 13); + auto const parsed = Map->ParseUnitData(data, unit); + ASSERT(parsed); - if (Map->GetUnitAt(atoi(unit.x) + atoi(unit.y) * Map->GetIsoSize()) >= 0) { + if (Map->GetUnitAt(atoi(unit.basic.x) + atoi(unit.basic.y) * Map->GetIsoSize()) >= 0) { report += "AddVehicle failed\r\n"; goto nextline; } @@ -2444,20 +2421,10 @@ void CUserScriptsDlg::OnOK() CString data = params[0]; AIRCRAFT air; - air.house = GetParam(data, 0); - air.type = GetParam(data, 1); - air.strength = GetParam(data, 2); - air.y = GetParam(data, 3); - air.x = GetParam(data, 4); - air.direction = GetParam(data, 5); - air.action = GetParam(data, 6); - air.tag = GetParam(data, 7); - air.flag1 = GetParam(data, 8); - air.group = GetParam(data, 9); - air.flag3 = GetParam(data, 10); - air.flag4 = GetParam(data, 11); + auto const parsed = Map->ParseAircraftData(data, air); + ASSERT(parsed); - if (Map->GetAirAt(atoi(air.x) + atoi(air.y) * Map->GetIsoSize()) >= 0) { + if (Map->GetAirAt(atoi(air.basic.x) + atoi(air.basic.y) * Map->GetIsoSize()) >= 0) { report += "AddAircraft failed\r\n"; goto nextline; } @@ -2498,25 +2465,10 @@ void CUserScriptsDlg::OnOK() CString data = params[0]; STRUCTURE structure; - structure.house = GetParam(data, 0); - structure.type = GetParam(data, 1); - structure.strength = GetParam(data, 2); - structure.y = GetParam(data, 3); - structure.x = GetParam(data, 4); - structure.direction = GetParam(data, 5); - structure.tag = GetParam(data, 6); - structure.flag1 = GetParam(data, 7); - structure.flag2 = GetParam(data, 8); - structure.energy = GetParam(data, 9); - structure.upgradecount = GetParam(data, 10); - structure.spotlight = GetParam(data, 11); - structure.upgrade1 = GetParam(data, 12); - structure.upgrade2 = GetParam(data, 13); - structure.upgrade3 = GetParam(data, 14); - structure.flag3 = GetParam(data, 15); - structure.flag4 = GetParam(data, 16); + auto const parsed = Map->ParseStructureData(data, structure); + ASSERT(parsed); - if (Map->GetStructureAt(atoi(structure.x) + atoi(structure.y) * Map->GetIsoSize()) >= 0) { + if (Map->GetStructureAt(atoi(structure.basic.x) + atoi(structure.basic.y) * Map->GetIsoSize()) >= 0) { report += "AddStructure failed\r\n"; goto nextline; } diff --git a/MissionEditor/data/FinalAlert2/FALanguage.ini b/MissionEditor/data/FinalAlert2/FALanguage.ini index 23439f5..d36ed54 100644 --- a/MissionEditor/data/FinalAlert2/FALanguage.ini +++ b/MissionEditor/data/FinalAlert2/FALanguage.ini @@ -711,6 +711,7 @@ TaskforceDeleteMsgDesc=Are you sure to delete the selected task force? If you de IsoCaption=Map view ; iso view status bar +TerrainStatus=Terrain type: StructStatus=Structure: InfStatus=Infantry: AirStatus=Aircraft: @@ -1661,6 +1662,7 @@ TeamTypesOnlyTargetHouseEnemy=仅攻击当前敌对方 IsoCaption=地图视图 ; iso view status bar +TerrainStatus=地形: StructStatus=建筑: InfStatus=步兵: AirStatus=飞行器: