diff --git a/MissionEditor/IniFile.cpp b/MissionEditor/IniFile.cpp index 2d70bb3..5e29d25 100644 --- a/MissionEditor/IniFile.cpp +++ b/MissionEditor/IniFile.cpp @@ -180,30 +180,6 @@ WORD CIniFile::InsertFile(const std::string& filename, const char* Section, BOOL return 0; } -const CIniFileSection* CIniFile::TryGetSection(std::size_t index) const -{ - if (index > sections.size() - 1) - return NULL; - - auto i = sections.cbegin(); - for (auto e = 0;e < index;e++) - i++; - - return &i->second; -} - -CIniFileSection* CIniFile::TryGetSection(std::size_t index) -{ - if (index > sections.size() - 1) - return NULL; - - CIniI i = sections.begin(); - for (auto e = 0;e < index;e++) - i++; - - return &i->second; -} - const CString* CIniFile::GetSectionName(std::size_t index) const noexcept { if (index > sections.size() - 1) @@ -265,20 +241,8 @@ int CIniFileSection::FindIndex(const CString& key) const noexcept CString CIniFile::GetValueByName(const CString& sectionName, const CString& valueName, const CString& defaultValue) const { auto section = TryGetSection(sectionName); - if (!section) + if (!section) { return defaultValue; - return section->GetValueByName(valueName, defaultValue); + } + return section->GetStringOr(valueName, defaultValue); } - -int CIniFileSection::GetValueOrigPos(int index) const noexcept -{ - if (index > value_orig_pos.size() - 1) - return -1; - - auto i = value_orig_pos.cbegin(); - for (int e = 0;e < index;e++) - i++; - - return i->second; -} - diff --git a/MissionEditor/IniFile.h b/MissionEditor/IniFile.h index 65edaa9..0ce5945 100644 --- a/MissionEditor/IniFile.h +++ b/MissionEditor/IniFile.h @@ -78,6 +78,14 @@ public: return nullptr; } + const std::pair TryGetInteger(const CString& key) const { + auto const got = this->TryGetString(key); + if (!got) { + return {}; + } + return { INIHelper::StringToInteger(*got, 0), true }; + } + const CString& GetString(const CString& key) const { if (auto const ret = TryGetString(key)) { return *ret; @@ -92,10 +100,15 @@ public: return defaultValue; } - int GetInteger(const CString& key, int def = 0)const { + int GetInteger(const CString& key, int def = 0) const { return INIHelper::StringToInteger(this->GetString(key), def); } + bool GetBool(const CString& key, bool def = false) const { + auto const& str = this->GetString(key); + return INIHelper::StringToBool(str, def); + } + size_t Size() const { return value_pos.size(); } bool Exists(const CString& key) const { @@ -121,6 +134,17 @@ public: value_pairs[it->second].second = std::move(value); } + void Insert(const CString& key, const CString& value) { + this->Insert(key, CString(value)); + } + + void Insert(const CString& key, CString&& value) { + value_pairs.push_back({ key, value }); + value_pos.insert_or_assign(key, value_pairs.size() - 1); + } + + // ==================== Delete + void RemoveAt(size_t idx) { ASSERT(idx < value_pairs.size()); for (auto affectedIdx = idx + 1; affectedIdx < value_pairs.size(); ++affectedIdx) { @@ -130,7 +154,7 @@ public: it->second--; } auto const itErased = value_pairs.erase(value_pairs.begin() + idx); - ASSERT(value_pos.erase(itErased->first), 1); + ASSERT(value_pos.erase(itErased->first) == 1); } void RemoveByKey(const CString& key) { @@ -155,9 +179,6 @@ public: return value_pairs.end(); } - [[deprecated("instead use iterators or for_each")]] - int GetValueOrigPos(int index) const noexcept; - [[deprecated("instead use iterators or for_each")]] const CString* GetValueName(std::size_t index) const noexcept { return &Nth(index).first; @@ -176,6 +197,24 @@ class CIniFile static const CIniFileSection EmptySection; public: + CIniFile(CIniFile&& rhs) : + m_filename(std::move(rhs.m_filename)), + sections(std::move(rhs.sections)) + {} + CIniFile(const CIniFile& rhs) : + m_filename(rhs.m_filename), + sections(rhs.sections) + {} + + CIniFile& operator=(CIniFile&& rhs) { + new (this)CIniFile(std::move(rhs)); + return *this; + } + CIniFile& operator=(const CIniFile& rhs) { + new (this)CIniFile(rhs); + return *this; + } + [[deprecated("instead use GetString")]] CString GetValueByName(const CString& sectionName, const CString& valueName, const CString& defaultValue) const; void Clear(); @@ -189,9 +228,6 @@ public: // ================ Section interfaces ================ const CString* GetSectionName(std::size_t Index) const noexcept; - const CIniFileSection* TryGetSection(std::size_t index) const; - CIniFileSection* TryGetSection(std::size_t index); - const CIniFileSection* TryGetSection(const CString& section) const { auto pMutThis = const_cast>*>(this); @@ -232,8 +268,7 @@ public: return GetSection(section).GetString(key); } const bool GetBool(const CString& section, const CString& key, bool def = false) const { - auto const& str = this->GetString(section, key); - return INIHelper::StringToBool(str, def); + return this->GetSection(section).GetBool(key, def); } const int GetInteger(const CString& section, const CString& key, int def = 0) const { return GetSection(section).GetInteger(key, def); @@ -259,6 +294,14 @@ public: return this->SetString(section, key, CString(value)); } + void SetBool(const CString& section, const CString& key, const bool value) { + this->SetString(section, key, INIHelper::ToString(value)); + } + + auto Size() const noexcept { + return this->sections.size(); + } + auto begin() noexcept { return sections.begin(); diff --git a/MissionEditor/IniHelper.h b/MissionEditor/IniHelper.h index e29b1b4..f53a1dd 100644 --- a/MissionEditor/IniHelper.h +++ b/MissionEditor/IniHelper.h @@ -28,4 +28,14 @@ public: } return def; } + + template + static CString ToString(const T& origin);// { static_assert(false, "T must have specialized implementations!"); } + + template<> + static CString ToString(const bool& origin) + { + static CString result[] = { "false", "true" }; + return result[origin]; + } }; \ No newline at end of file diff --git a/MissionEditor/Loading.cpp b/MissionEditor/Loading.cpp index f41bd9b..3d8b3fd 100644 --- a/MissionEditor/Loading.cpp +++ b/MissionEditor/Loading.cpp @@ -249,13 +249,12 @@ void CLoading::Load() } } #else - if(bUseFirestorm && yuri_mode) // MW actually this is Yuri's Revenge - { + // MW actually this is Yuri's Revenge + if (bUseFirestorm && yuri_mode) { CIniFile rulesmd; LoadTSIni("rulesmd.ini", &rulesmd, TRUE); - if(rulesmd.sections.size()>0) - { - rules=rulesmd; + if (rulesmd.Size() > 0) { + rules = std::move(rulesmd); } } #endif @@ -321,10 +320,8 @@ void CLoading::Load() { CIniFile artmd; LoadTSIni("artmd.ini", &artmd, TRUE); - if(artmd.sections.size()>0) - { - art.Clear(); - art=artmd; + if(artmd.Size()>0) { + art = std::move(artmd); } } #endif @@ -348,8 +345,7 @@ void CLoading::Load() UpdateWindow(); - if(bUseFirestorm) - { + if(bUseFirestorm) { int b; for(b=99;b>0;b--) { @@ -361,11 +357,17 @@ void CLoading::Load() name+=".ini"; LoadTSIni(name, &sound, FALSE); - if(sound.sections.size()>0) break; + if (sound.Size() > 0) { + break; + } } - } else LoadTSIni("Sound01.ini", &sound, FALSE); - if(sound.sections.size()==0) LoadTSIni("Sound.ini", &sound, FALSE); + } else { + LoadTSIni("Sound01.ini", &sound, FALSE); + } + if (sound.Size() == 0) { + LoadTSIni("Sound.ini", &sound, FALSE); + } m_progress.SetPos(2); UpdateWindow(); @@ -440,8 +442,9 @@ void CLoading::Load() UpdateWindow(); // MW FIX: MAKE URBAN RAMPS MORPHABLE: - if(tiles_un.sections["TileSet0117"].FindName("Morphable")<0) - tiles_un.sections["TileSet0117"].values["Morphable"]="true"; + if (!tiles_un["TileSet0117"].Exists("Morphable")) { + tiles_un.SetBool("TileSet0117", "Morphable", true); + } m_cap.SetWindowText(GetLanguageStringACP("LoadLoadLunar")); m_progress.SetPos(1); @@ -536,7 +539,7 @@ void CLoading::InitPics(CProgressCtrl* prog) pics[(LPCTSTR)ff.GetFileName()].pic = BitmapToSurface(((CFinalSunDlg*)theApp.m_pMainWnd)->m_view.m_isoview->dd, *BitmapFromFile(ff.GetFilePath())).Detach(); DDSURFACEDESC2 desc; - memset(&desc, 0, sizeof(DDSURFACEDESC2)); + ::memset(&desc, 0, sizeof(DDSURFACEDESC2)); desc.dwSize = sizeof(DDSURFACEDESC2); desc.dwFlags = DDSD_HEIGHT | DDSD_WIDTH; ((LPDIRECTDRAWSURFACE4)pics[(LPCTSTR)ff.GetFileName()].pic)->GetSurfaceDesc(&desc); @@ -566,7 +569,7 @@ void CLoading::InitPics(CProgressCtrl* prog) try { pics["SCROLLCURSOR"].pic = BitmapToSurface(((CFinalSunDlg*)theApp.m_pMainWnd)->m_view.m_isoview->dd, *BitmapFromResource(IDB_SCROLLCURSOR)).Detach(); FSunPackLib::SetColorKey((LPDIRECTDRAWSURFACE4)pics["SCROLLCURSOR"].pic, -1); - memset(&desc, 0, sizeof(DDSURFACEDESC2)); + ::memset(&desc, 0, sizeof(DDSURFACEDESC2)); desc.dwSize = sizeof(DDSURFACEDESC2); desc.dwFlags = DDSD_HEIGHT | DDSD_WIDTH; ((LPDIRECTDRAWSURFACE4)pics["SCROLLCURSOR"].pic)->GetSurfaceDesc(&desc); @@ -581,7 +584,7 @@ void CLoading::InitPics(CProgressCtrl* prog) try { pics["CELLTAG"].pic = BitmapToSurface(((CFinalSunDlg*)theApp.m_pMainWnd)->m_view.m_isoview->dd, *BitmapFromResource(IDB_CELLTAG)).Detach(); FSunPackLib::SetColorKey((LPDIRECTDRAWSURFACE4)pics["CELLTAG"].pic, CLR_INVALID); - memset(&desc, 0, sizeof(DDSURFACEDESC2)); + ::memset(&desc, 0, sizeof(DDSURFACEDESC2)); desc.dwSize = sizeof(DDSURFACEDESC2); desc.dwFlags = DDSD_HEIGHT | DDSD_WIDTH; ((LPDIRECTDRAWSURFACE4)pics["CELLTAG"].pic)->GetSurfaceDesc(&desc); @@ -604,7 +607,7 @@ void CLoading::InitPics(CProgressCtrl* prog) { pics["FLAG"].pic = BitmapToSurface(((CFinalSunDlg*)theApp.m_pMainWnd)->m_view.m_isoview->dd, *BitmapFromResource(IDB_FLAG)).Detach(); FSunPackLib::SetColorKey((LPDIRECTDRAWSURFACE4)pics["FLAG"].pic, -1); - memset(&desc, 0, sizeof(DDSURFACEDESC2)); + ::memset(&desc, 0, sizeof(DDSURFACEDESC2)); desc.dwSize = sizeof(DDSURFACEDESC2); desc.dwFlags = DDSD_HEIGHT | DDSD_WIDTH; ((LPDIRECTDRAWSURFACE4)pics["FLAG"].pic)->GetSurfaceDesc(&desc); @@ -621,7 +624,7 @@ void CLoading::InitPics(CProgressCtrl* prog) // MW April 2nd, 2001 // prepare 1x1 hidden tile replacement DDSURFACEDESC2 ddsd; - memset(&ddsd, 0, sizeof(DDSURFACEDESC2)); + ::memset(&ddsd, 0, sizeof(DDSURFACEDESC2)); ddsd.dwSize=sizeof(DDSURFACEDESC2); ddsd.ddsCaps.dwCaps=DDSCAPS_OFFSCREENPLAIN; ddsd.dwFlags=DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH; @@ -669,10 +672,8 @@ void CLoading::InitPics(CProgressCtrl* prog) // new: Prepare building terrain information: - int i; - for(i=0;i CLoading::FindUnitShp(const CString& image, char pr const bool firstCharSupportsTheater = first == 'G' || first == 'N' || first == 'C' || first == 'Y'; HTSPALETTE forcedPalette = 0; - const auto& unitPalettePrefixes = g_data.sections["ForceUnitPalettePrefix"]; - if (unitPalettePrefixes.end() != std::find_if(unitPalettePrefixes.begin(), unitPalettePrefixes.end(), [&image](const auto& pair) {return image.Find(pair.second) == 0;})) - { + const auto& unitPalettePrefixes = g_data["ForceUnitPalettePrefix"]; + if (unitPalettePrefixes.end() != std::find_if(unitPalettePrefixes.begin(), unitPalettePrefixes.end(), + [&image](const auto& pair) {return image.Find(pair.second) == 0; })) { forcedPalette = GetUnitPalette(preferred_theat); } - const auto& isoPalettePrefixes = g_data.sections["ForceIsoPalettePrefix"]; - if (isoPalettePrefixes.end() != std::find_if(isoPalettePrefixes.begin(), isoPalettePrefixes.end(), [&image](const auto& pair) {return image.Find(pair.second) == 0;})) - { + const auto& isoPalettePrefixes = g_data["ForceIsoPalettePrefix"]; + if (isoPalettePrefixes.end() != std::find_if(isoPalettePrefixes.begin(), isoPalettePrefixes.end(), + [&image](const auto& pair) {return image.Find(pair.second) == 0;})) { forcedPalette = GetIsoPalette(preferred_theat); } - const bool isTheater = isTrue(artSection.GetValueByName("Theater")); - const bool isNewTheater = isTrue(artSection.GetValueByName("NewTheater")); - const bool terrainPalette = isTrue(artSection.GetValueByName("TerrainPalette")); + const bool isTheater = artSection.GetBool("Theater"); + const bool isNewTheater = artSection.GetBool("NewTheater"); + const bool terrainPalette = artSection.GetBool("TerrainPalette"); auto unitOrIsoPalette = terrainPalette ? GetIsoPalette(preferred_theat) : GetUnitPalette(preferred_theat); @@ -1281,7 +1287,7 @@ int lepton_to_screen_y(int leptons) return leptons * f_y / 256; } -BOOL CLoading::LoadUnitGraphic(LPCTSTR lpUnittype) +BOOL CLoading::LoadUnitGraphic(const CString& lpUnittype) { errstream << "Loading: " << lpUnittype << endl; errstream.flush(); @@ -1296,31 +1302,34 @@ BOOL CLoading::LoadUnitGraphic(LPCTSTR lpUnittype) WORD wStep=1; // step is 1 for infantry, buildings, etc, and for shp vehicles it specifies the step rate between every direction WORD wStartWalkFrame=0; // for examply cyborg reaper has another walk starting frame int iTurretOffset=0; // used for centering y pos of turret (if existing) (for vehicles) - const BOOL bStructure=rules.sections["BuildingTypes"].FindValue(lpUnittype)>=0; // is this a structure? - const BOOL bVehicle = rules.sections["VehicleTypes"].FindValue(lpUnittype) >= 0; // is this a structure? + const BOOL bStructure = rules["BuildingTypes"].HasValue(lpUnittype); // is this a structure? + const BOOL bVehicle = rules["VehicleTypes"].HasValue(lpUnittype); // is this a structure? - BOOL bPowerUp=rules.sections[lpUnittype].values["PowersUpBuilding"]!=""; + auto const bPowerUp = !rules.GetString(lpUnittype, "PowersUpBuilding").IsEmpty(); CIsoView& v=*((CFinalSunDlg*)theApp.m_pMainWnd)->m_view.m_isoview; _rules_image=lpUnittype; - if(rules.sections[lpUnittype].values.find("Image")!=rules.sections[lpUnittype].values.end()) - _rules_image=rules.sections[lpUnittype].values["Image"]; + auto const imageID = rules.GetString(lpUnittype, "Image"); + if (!imageID.IsEmpty()) { + _rules_image = imageID; + } CString _art_image = _rules_image; - if(art.sections[_rules_image].values.find("Image")!=art.sections[_rules_image].values.end()) - { - if(!isTrue(g_data.sections["IgnoreArtImage"].values[_rules_image])) - _art_image=art.sections[_rules_image].values["Image"]; + auto const& imageID = art.GetString(_rules_image, "Image"); + if (!imageID.IsEmpty()) { + if (!g_data.GetBool("IgnoreArtImage", _rules_image)) { + _art_image = imageID; + } } const CString& image = _art_image; - const auto& rulesSection = rules.sections[lpUnittype]; - const auto& artSection = art.sections[image]; + const auto& rulesSection = rules[lpUnittype]; + const auto& artSection = art[image]; - if(!isTrue(art.sections[image].values["Voxel"])) // is it a shp graphic? - { + // is it a shp graphic? + if (!artSection.GetBool(image, "Voxel")) { try { @@ -1337,7 +1346,7 @@ BOOL CLoading::LoadUnitGraphic(LPCTSTR lpUnittype) HTSPALETTE hPalette = shp->palette; const auto hShpMix = shp->mixfile; theat = static_cast(shp->theat); - auto limited_to_theater = isTrue(artSection.GetValueByName("TerrainPalette")) ? shp->mixfile_theater : TheaterChar::None; + auto limited_to_theater = artSection.GetBool("TerrainPalette") ? shp->mixfile_theater : TheaterChar::None; SHPHEADER head; @@ -1399,9 +1408,8 @@ BOOL CLoading::LoadUnitGraphic(LPCTSTR lpUnittype) } //hShpMix=20; - - if(rules.sections[lpUnittype].values["Bib"]!="no") // seems to be ignored by TS, art.ini overwrites??? - { + // seems to be ignored by TS, art.ini overwrites??? + if(rules.GetBool( lpUnittype, "Bib")) { LoadBuildingSubGraphic("BibShape", artSection, bAlwaysSetChar, theat, hShpMix, bib_h, bib); } @@ -1409,13 +1417,13 @@ BOOL CLoading::LoadUnitGraphic(LPCTSTR lpUnittype) LoadBuildingSubGraphic("IdleAnim", artSection, bAlwaysSetChar, theat, hShpMix, idleanim_h, idleanim); LoadBuildingSubGraphic("ActiveAnim2", artSection, bAlwaysSetChar, theat, hShpMix, activeanim2_h, activeanim2); LoadBuildingSubGraphic("ActiveAnim3", artSection, bAlwaysSetChar, theat, hShpMix, activeanim3_h, activeanim3); - if (!isTrue(g_data.sections["IgnoreSuperAnim1"].values[image])) + if (!g_data.GetBool("IgnoreSuperAnim1", image)) LoadBuildingSubGraphic("SuperAnim", artSection, bAlwaysSetChar, theat, hShpMix, superanim1_h, superanim1); - if (!isTrue(g_data.sections["IgnoreSuperAnim2"].values[image])) + if (!g_data.GetBool("IgnoreSuperAnim2", image)) LoadBuildingSubGraphic("SuperAnimTwo", artSection, bAlwaysSetChar, theat, hShpMix, superanim2_h, superanim2); - if (!isTrue(g_data.sections["IgnoreSuperAnim3"].values[image])) + if (!g_data.GetBool("IgnoreSuperAnim3", image)) LoadBuildingSubGraphic("SuperAnimThree", artSection, bAlwaysSetChar, theat, hShpMix, superanim3_h, superanim3); - if (!isTrue(g_data.sections["IgnoreSuperAnim4"].values[image])) + if (!g_data.GetBool("IgnoreSuperAnim4", image)) LoadBuildingSubGraphic("SuperAnimFour", artSection, bAlwaysSetChar, theat, hShpMix, superanim4_h, superanim4); LoadBuildingSubGraphic("SpecialAnim", artSection, bAlwaysSetChar, theat, hShpMix, specialanim1_h, specialanim1); LoadBuildingSubGraphic("SpecialAnimTwo", artSection, bAlwaysSetChar, theat, hShpMix, specialanim2_h, specialanim2); @@ -1427,21 +1435,23 @@ BOOL CLoading::LoadUnitGraphic(LPCTSTR lpUnittype) FSunPackLib::VoxelNormalClass vnc = FSunPackLib::VoxelNormalClass::Unknown; - if (isTrue(rules.sections[image].values["Turret"])) - { - turretanim_name = rules.sections[image].values["TurretAnim"]; + if (rules.GetBool(image, "Turret")) { + turretanim_name = rules.GetString(image, "TurretAnim"); auto vxl_turretanim_filename = turretanim_name.IsEmpty() ? image + "tur.vxl" : turretanim_name + ".vxl"; auto vxl_barrelanim_filename = image + "barl.vxl"; - if (art.sections[turretanim_name].values.find("Image") != art.sections[turretanim_name].values.end()) - vxl_turretanim_filename = art.sections[turretanim_name].values["Image"] + ".vxl"; + auto const& imageID = art.GetString(turretanim_name, "Image"); + if (!imageID.IsEmpty()) { + vxl_turretanim_filename = imageID + ".vxl"; + } - if (bStructure && turretanim_name.GetLength() > 0 && isFalse(rules.sections[image].values["TurretAnimIsVoxel"])) - { + if (bStructure && turretanim_name.GetLength() > 0 && !rules.GetBool(image, "TurretAnimIsVoxel")) { turretanim_filename = turretanim_name + ".shp"; - if (art.sections[turretanim_name].values.find("Image") != art.sections[turretanim_name].values.end()) turretanim_filename = art.sections[turretanim_name].values["Image"] + ".shp"; + auto const& imageID = art.GetString(turretanim_name, "Image"); + if (imageID.IsEmpty()) { + turretanim_filename = imageID + ".shp"; + } - if (isTrue(artSection.GetValueByName("NewTheater"))) - { + if (artSection.GetBool("NewTheater")) { auto tmp = turretanim_filename; tmp.SetAt(1, theat); if (FSunPackLib::XCC_DoesFileExist(tmp, hShpMix)) @@ -1468,20 +1478,17 @@ BOOL CLoading::LoadUnitGraphic(LPCTSTR lpUnittype) } } - } - else if ( - (bStructure && turretanim_name.GetLength() > 0 && isTrue(rules.sections[image].values["TurretAnimIsVoxel"])) + } else if ( + (bStructure && turretanim_name.GetLength() > 0 && rules.GetBool(image, "TurretAnimIsVoxel")) || (!bStructure && (FindFileInMix(vxl_turretanim_filename) || FindFileInMix(vxl_barrelanim_filename))) - ) - { + ) { turretanim_filename = vxl_turretanim_filename; barrelanim_filename = vxl_barrelanim_filename; HMIXFILE hVXL = FindFileInMix(vxl_turretanim_filename); HMIXFILE hBarl = FindFileInMix(vxl_barrelanim_filename); - if (artSection.values.find("TurretOffset") != art.sections[image].values.end()) - iTurretOffset = atoi(art.sections[image].values["TurretOffset"]); + iTurretOffset = artSection.GetInteger("TurretOffset", iTurretOffset); Vec3f turretModelOffset(iTurretOffset / 6.0f, 0.0f, 0.0f); @@ -1567,7 +1574,17 @@ BOOL CLoading::LoadUnitGraphic(LPCTSTR lpUnittype) RECT r; int center_x, center_y; if (! - FSunPackLib::LoadVXLImage(*m_voxelNormalTables, lightDirection, rotation, turretModelOffset, vxlBarrelColors[i], vxlBarrelLighting[i], ¢er_x, ¢er_y, atoi(rules.sections[image].values["TurretAnimZAdjust"]), 0, 0, 0, 0, &r) + FSunPackLib::LoadVXLImage( + *m_voxelNormalTables, + lightDirection, + rotation, + turretModelOffset, + vxlBarrelColors[i], + vxlBarrelLighting[i], + ¢er_x, + ¢er_y, + rules.GetInteger(image, "TurretAnimZAdjust"), + 0, 0, 0, 0, &r) ) { @@ -1591,21 +1608,21 @@ BOOL CLoading::LoadUnitGraphic(LPCTSTR lpUnittype) } - if(art.sections[image].values.find("WalkFrames")!=art.sections[image].values.end()) - wStep=atoi(art.sections[image].values["WalkFrames"]); - if(art.sections[image].values.find("StartWalkFrame")!=art.sections[image].values.end()) - wStartWalkFrame=atoi(art.sections[image].values["StartWalkFrame"]); + wStep = art.GetInteger(image, "WalkFrames", wStep); + wStartWalkFrame = art.GetInteger(image, "StartWalkFrame", wStartWalkFrame); - if(art.sections[image].values["Palette"]=="lib") - hPalette=m_hPalLib; + if (art.GetString(image, "Palette") == "lib") { + hPalette = m_hPalLib; + } BOOL bSuccess=FSunPackLib::SetCurrentSHP(filename, hShpMix); if( !bSuccess - ) - { + ) { filename=image+".sno"; - if(cur_theat=='T' || cur_theat=='U' /* || cur_theat=='N' ? */) hPalette=m_hPalIsoTemp; + if (cur_theat == 'T' || cur_theat == 'U' /* || cur_theat=='N' ? */) { + hPalette = m_hPalIsoTemp; + } HMIXFILE hShpMix=FindFileInMix(filename); bSuccess=FSunPackLib::SetCurrentSHP(filename, hShpMix); @@ -1615,42 +1632,38 @@ BOOL CLoading::LoadUnitGraphic(LPCTSTR lpUnittype) } } - if(bSuccess) - { - - FSunPackLib::XCC_GetSHPHeader(&head); - int i; - int maxPics=head.c_images; - if(maxPics>8) maxPics=8; // we only need 8 pictures for every direction! - if(bStructure && !bPowerUp && !isTrue(rules.sections[image].values["Turret"])) maxPics=1; - if(bVoxelTurret) maxPics=8; - + if (bSuccess) { - - if(!bStructure && rules.sections[image].values["Turret"]=="yes") - { - int iStartTurret=wStartWalkFrame+8*wStep; - const WORD wAnimCount=4; // anims between each "normal" direction, seems to be hardcoded - + FSunPackLib::XCC_GetSHPHeader(&head); int i; - - for(i=0;i<8;i++) - { - if(iStartTurret+i*wAnimCount 8) { + maxPics = 8; // we only need 8 pictures for every direction! + } + if (bStructure && !bPowerUp && !rules.GetBool(image, "Turret")) { + maxPics = 1; + } + if (bVoxelTurret) { + maxPics = 8; + } + + if (!bStructure && rules.GetBool(image, "Turret")) { + int iStartTurret = wStartWalkFrame + 8 * wStep; + const WORD wAnimCount = 4; // anims between each "normal" direction, seems to be hardcoded + for (auto i = 0; i < 8; i++) { + if (iStartTurret + i * wAnimCount < head.c_images) { + FSunPackLib::XCC_GetSHPImageHeader(iStartTurret + i * wAnimCount, &turretinfo[i]); + FSunPackLib::XCC_GetSHPHeader(&turrets_h[i]); + FSunPackLib::LoadSHPImage(iStartTurret + i * wAnimCount, turretColors[i]); + } + } } - } // create an array of pointers to directdraw surfaces lpT=new(BYTE*[maxPics]); - memset(lpT, 0, sizeof(BYTE)*maxPics); + ::memset(lpT, 0, sizeof(BYTE)*maxPics); std::vector> lighting(maxPics); std::vector shp_image_headers(maxPics); @@ -1661,19 +1674,16 @@ BOOL CLoading::LoadUnitGraphic(LPCTSTR lpUnittype) FSunPackLib::LoadSHPImage(0, 1, &lpT[i]); FSunPackLib::XCC_GetSHPImageHeader(0, &shp_image_headers[i]); } - } - else if(wStep==1 && (rules.sections[lpUnittype].values["PowersUpBuilding"].GetLength()==0 || !isTrue(rules.sections[lpUnittype].values["Turret"]))) - { // standard case... - + } else if(wStep==1 && (rules.GetString(lpUnittype, "PowersUpBuilding").IsEmpty() || !rules.GetBool( lpUnittype,"Turret"))) { + // standard case... FSunPackLib::LoadSHPImage(wStartWalkFrame, maxPics, lpT); - for (int i = 0; i < maxPics; ++i) + for (int i = 0; i < maxPics; ++i) { FSunPackLib::XCC_GetSHPImageHeader(wStartWalkFrame + i, &shp_image_headers[i]); + } - } - else if(rules.sections[lpUnittype].values["PowersUpBuilding"].GetLength()!=0 && isTrue(rules.sections[lpUnittype].values["Turret"])) - { // a "real" turret (vulcan cannon, etc...) - for(i=0;iBlt(NULL, bib, NULL, DDBLT_KEYSRC | DDBLT_WAIT , &fx); @@ -1716,7 +1726,7 @@ BOOL CLoading::LoadUnitGraphic(LPCTSTR lpUnittype) { DDBLTFX fx; - memset(&fx, 0, sizeof(DDBLTFX)); + ::memset(&fx, 0, sizeof(DDBLTFX)); fx.dwSize=sizeof(DDBLTFX); //lpT[i]->Blt(NULL, activeanim, NULL, DDBLT_KEYSRC | DDBLT_WAIT , &fx); @@ -1729,7 +1739,7 @@ BOOL CLoading::LoadUnitGraphic(LPCTSTR lpUnittype) { DDBLTFX fx; - memset(&fx, 0, sizeof(DDBLTFX)); + ::memset(&fx, 0, sizeof(DDBLTFX)); fx.dwSize=sizeof(DDBLTFX); //lpT[i]->Blt(NULL, idleanim, NULL, DDBLT_KEYSRC | DDBLT_WAIT , &fx); @@ -1742,7 +1752,7 @@ BOOL CLoading::LoadUnitGraphic(LPCTSTR lpUnittype) { DDBLTFX fx; - memset(&fx, 0, sizeof(DDBLTFX)); + ::memset(&fx, 0, sizeof(DDBLTFX)); fx.dwSize=sizeof(DDBLTFX); //lpT[i]->Blt(NULL, activeanim2, NULL, DDBLT_KEYSRC | DDBLT_WAIT , &fx); @@ -1754,7 +1764,7 @@ BOOL CLoading::LoadUnitGraphic(LPCTSTR lpUnittype) { DDBLTFX fx; - memset(&fx, 0, sizeof(DDBLTFX)); + ::memset(&fx, 0, sizeof(DDBLTFX)); fx.dwSize=sizeof(DDBLTFX); //lpT[i]->Blt(NULL, activeanim3, NULL, DDBLT_KEYSRC | DDBLT_WAIT , &fx); @@ -1766,7 +1776,7 @@ BOOL CLoading::LoadUnitGraphic(LPCTSTR lpUnittype) { DDBLTFX fx; - memset(&fx, 0, sizeof(DDBLTFX)); + ::memset(&fx, 0, sizeof(DDBLTFX)); fx.dwSize=sizeof(DDBLTFX); //lpT[i]->Blt(NULL, superanim1, NULL, DDBLT_KEYSRC | DDBLT_WAIT , &fx); @@ -1779,7 +1789,7 @@ BOOL CLoading::LoadUnitGraphic(LPCTSTR lpUnittype) { DDBLTFX fx; - memset(&fx, 0, sizeof(DDBLTFX)); + ::memset(&fx, 0, sizeof(DDBLTFX)); fx.dwSize=sizeof(DDBLTFX); //lpT[i]->Blt(NULL, superanim2, NULL, DDBLT_KEYSRC | DDBLT_WAIT , &fx); @@ -1792,7 +1802,7 @@ BOOL CLoading::LoadUnitGraphic(LPCTSTR lpUnittype) { DDBLTFX fx; - memset(&fx, 0, sizeof(DDBLTFX)); + ::memset(&fx, 0, sizeof(DDBLTFX)); fx.dwSize=sizeof(DDBLTFX); //lpT[i]->Blt(NULL, superanim3, NULL, DDBLT_KEYSRC | DDBLT_WAIT , &fx); @@ -1805,7 +1815,7 @@ BOOL CLoading::LoadUnitGraphic(LPCTSTR lpUnittype) { DDBLTFX fx; - memset(&fx, 0, sizeof(DDBLTFX)); + ::memset(&fx, 0, sizeof(DDBLTFX)); fx.dwSize=sizeof(DDBLTFX); //lpT[i]->Blt(NULL, superanim4, NULL, DDBLT_KEYSRC | DDBLT_WAIT , &fx); @@ -1818,7 +1828,7 @@ BOOL CLoading::LoadUnitGraphic(LPCTSTR lpUnittype) { DDBLTFX fx; - memset(&fx, 0, sizeof(DDBLTFX)); + ::memset(&fx, 0, sizeof(DDBLTFX)); fx.dwSize=sizeof(DDBLTFX); //lpT[i]->Blt(NULL, specialanim1, NULL, DDBLT_KEYSRC | DDBLT_WAIT , &fx); @@ -1831,7 +1841,7 @@ BOOL CLoading::LoadUnitGraphic(LPCTSTR lpUnittype) { DDBLTFX fx; - memset(&fx, 0, sizeof(DDBLTFX)); + ::memset(&fx, 0, sizeof(DDBLTFX)); fx.dwSize=sizeof(DDBLTFX); //lpT[i]->Blt(NULL, specialanim2, NULL, DDBLT_KEYSRC | DDBLT_WAIT , &fx); @@ -1843,7 +1853,7 @@ BOOL CLoading::LoadUnitGraphic(LPCTSTR lpUnittype) { DDBLTFX fx; - memset(&fx, 0, sizeof(DDBLTFX)); + ::memset(&fx, 0, sizeof(DDBLTFX)); fx.dwSize=sizeof(DDBLTFX); //lpT[i]->Blt(NULL, specialanim3, NULL, DDBLT_KEYSRC | DDBLT_WAIT , &fx); @@ -1856,7 +1866,7 @@ BOOL CLoading::LoadUnitGraphic(LPCTSTR lpUnittype) { DDBLTFX fx; - memset(&fx, 0, sizeof(DDBLTFX)); + ::memset(&fx, 0, sizeof(DDBLTFX)); fx.dwSize=sizeof(DDBLTFX); //lpT[i]->Blt(NULL, specialanim4, NULL, DDBLT_KEYSRC | DDBLT_WAIT , &fx); @@ -1871,7 +1881,7 @@ BOOL CLoading::LoadUnitGraphic(LPCTSTR lpUnittype) if(!vxlBarrelColors[i].empty() && (i == 1 || i == 0 || i == 7)) { DDSURFACEDESC2 ddsd; - memset(&ddsd, 0, sizeof(DDSURFACEDESC2)); + ::memset(&ddsd, 0, sizeof(DDSURFACEDESC2)); ddsd.dwSize = sizeof(DDSURFACEDESC2); ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT; ddsd.dwWidth = barrels_h[i].cx; @@ -1881,19 +1891,19 @@ BOOL CLoading::LoadUnitGraphic(LPCTSTR lpUnittype) char c[50]; itoa(i, c, 10); #ifdef RA2_MODE - XMover = atoi(g_data.sections["BuildingVoxelBarrelsRA2"].values[(CString)lpUnittype + "X"]); - YMover = atoi(g_data.sections["BuildingVoxelBarrelsRA2"].values[(CString)lpUnittype + "Y"]); - XMover += atoi(g_data.sections["BuildingVoxelBarrelsRA2"].values[(CString)lpUnittype + (CString)"X" + c]); - YMover += atoi(g_data.sections["BuildingVoxelBarrelsRA2"].values[(CString)lpUnittype + (CString)"Y" + c]); + XMover = g_data.GetInteger("BuildingVoxelBarrelsRA2", lpUnittype + "X"); + YMover = g_data.GetInteger("BuildingVoxelBarrelsRA2", lpUnittype + "Y"); + XMover += g_data.GetInteger("BuildingVoxelBarrelsRA2", lpUnittype + "X" + c); + YMover += g_data.GetInteger("BuildingVoxelBarrelsRA2", lpUnittype + "Y" + c); #else - XMover = atoi(g_data.sections["BuildingVoxelBarrels"].values[(CString)lpUnittype + "X"]); - YMover = atoi(g_data.sections["BuildingVoxelBarrels"].values[(CString)lpUnittype + "Y"]); + XMover = atoi(g_data.GetInteger("BuildingVoxelBarrels"].lpUnittype + "X"); + YMover = atoi(g_data.GetInteger("BuildingVoxelBarrels"].lpUnittype + "Y"); #endif RECT srcRect, destRect; - int mx = head.cx / 2 + atoi(rules.sections[image].values["TurretAnimX"]) - barrelinfo[i].x; - int my = head.cy / 2 + atoi(rules.sections[image].values["TurretAnimY"]) - barrelinfo[i].y; + int mx = head.cx / 2 + rules.GetInteger(image, "TurretAnimX") - barrelinfo[i].x; + int my = head.cy / 2 + rules.GetInteger(image, "TurretAnimY") - barrelinfo[i].y; srcRect.top = 0; srcRect.left = 0; @@ -1916,7 +1926,7 @@ BOOL CLoading::LoadUnitGraphic(LPCTSTR lpUnittype) if(!turretColors[i].empty()) { DDSURFACEDESC2 ddsd; - memset(&ddsd, 0, sizeof(DDSURFACEDESC2)); + ::memset(&ddsd, 0, sizeof(DDSURFACEDESC2)); ddsd.dwSize=sizeof(DDSURFACEDESC2); ddsd.dwFlags=DDSD_WIDTH | DDSD_HEIGHT; //turrets[i]->GetSurfaceDesc(&ddsd); @@ -1928,21 +1938,21 @@ BOOL CLoading::LoadUnitGraphic(LPCTSTR lpUnittype) char c[50]; itoa(i, c, 10); #ifdef RA2_MODE - XMover = atoi(g_data.sections["BuildingVoxelTurretsRA2"].values[(CString)lpUnittype + "X"]); - YMover = atoi(g_data.sections["BuildingVoxelTurretsRA2"].values[(CString)lpUnittype + "Y"]); - XMover += atoi(g_data.sections["BuildingVoxelTurretsRA2"].values[(CString)lpUnittype + (CString)"X" + c]); - YMover += atoi(g_data.sections["BuildingVoxelTurretsRA2"].values[(CString)lpUnittype + (CString)"Y" + c]); + XMover = g_data.GetInteger("BuildingVoxelTurretsRA2", lpUnittype + "X"); + YMover = g_data.GetInteger("BuildingVoxelTurretsRA2", lpUnittype + "Y"); + XMover += g_data.GetInteger("BuildingVoxelTurretsRA2", lpUnittype + "X" + c); + YMover += g_data.GetInteger("BuildingVoxelTurretsRA2", lpUnittype + "Y" + c); #else - XMover = atoi(g_data.sections["BuildingVoxelTurrets"].values[(CString)lpUnittype + "X"]); - YMover = atoi(g_data.sections["BuildingVoxelTurrets"].values[(CString)lpUnittype + "Y"]); + XMover = g_data.GetInteger("BuildingVoxelTurrets", lpUnittype + "X"); + YMover = g_data.GetInteger("BuildingVoxelTurrets", lpUnittype + "Y"); #endif RECT srcRect, destRect; if (bVoxelTurret) { - int mx = head.cx / 2 + atoi(rules.sections[image].values["TurretAnimX"]) - turretinfo[i].x; - int my = head.cy / 2 + atoi(rules.sections[image].values["TurretAnimY"]) - turretinfo[i].y; + int mx = head.cx / 2 + rules.GetInteger(image, "TurretAnimX") - turretinfo[i].x; + int my = head.cy / 2 + rules.GetInteger(image, "TurretAnimY") - turretinfo[i].y; srcRect.top=0; srcRect.left=0; @@ -1957,8 +1967,8 @@ BOOL CLoading::LoadUnitGraphic(LPCTSTR lpUnittype) else // !bVoxelTurret { - int mx = atoi(rules.sections[image].values["TurretAnimX"]); - int my = atoi(rules.sections[image].values["TurretAnimY"]);//+atoi(rules.sections[image].values["barrelAnimZAdjust"]); + int mx = rules.GetInteger(image, "TurretAnimX"); + int my = rules.GetInteger(image, "TurretAnimY");//+rules.GetInteger(image, "barrelAnimZAdjust"); @@ -1983,7 +1993,7 @@ BOOL CLoading::LoadUnitGraphic(LPCTSTR lpUnittype) if(!vxlBarrelColors[i].empty() && i!=1 && i!=0 && i!=7) { DDSURFACEDESC2 ddsd; - memset(&ddsd, 0, sizeof(DDSURFACEDESC2)); + ::memset(&ddsd, 0, sizeof(DDSURFACEDESC2)); ddsd.dwSize = sizeof(DDSURFACEDESC2); ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT; ddsd.dwWidth = barrels_h[i].cx; @@ -1993,19 +2003,19 @@ BOOL CLoading::LoadUnitGraphic(LPCTSTR lpUnittype) char c[50]; itoa(i, c, 10); #ifdef RA2_MODE - XMover = atoi(g_data.sections["BuildingVoxelBarrelsRA2"].values[(CString)lpUnittype + "X"]); - YMover = atoi(g_data.sections["BuildingVoxelBarrelsRA2"].values[(CString)lpUnittype + "Y"]); - XMover += atoi(g_data.sections["BuildingVoxelBarrelsRA2"].values[(CString)lpUnittype + (CString)"X" + c]); - YMover += atoi(g_data.sections["BuildingVoxelBarrelsRA2"].values[(CString)lpUnittype + (CString)"Y" + c]); + XMover = g_data.GetInteger("BuildingVoxelBarrelsRA2", lpUnittype + "X"); + YMover = g_data.GetInteger("BuildingVoxelBarrelsRA2", lpUnittype + "Y"); + XMover += g_data.GetInteger("BuildingVoxelBarrelsRA2", lpUnittype + (CString)"X" + c); + YMover += g_data.GetInteger("BuildingVoxelBarrelsRA2", lpUnittype + (CString)"Y" + c); #else - XMover = atoi(g_data.sections["BuildingVoxelBarrels"].values[(CString)lpUnittype + "X"]); - YMover = atoi(g_data.sections["BuildingVoxelBarrels"].values[(CString)lpUnittype + "Y"]); + XMover = g_data.GetInteger("BuildingVoxelBarrels", lpUnittype + "X"); + YMover = g_data.GetInteger("BuildingVoxelBarrels", lpUnittype + "Y"); #endif RECT srcRect, destRect; - int mx = head.cx / 2 + atoi(rules.sections[image].values["TurretAnimX"]) - barrelinfo[i].x; - int my = head.cy / 2 + atoi(rules.sections[image].values["TurretAnimY"]) - barrelinfo[i].y; + int mx = head.cx / 2 + rules.GetInteger(image, "TurretAnimX") - barrelinfo[i].x; + int my = head.cy / 2 + rules.GetInteger(image, "TurretAnimY") - barrelinfo[i].y; srcRect.top = 0; srcRect.left = 0; @@ -2025,8 +2035,7 @@ BOOL CLoading::LoadUnitGraphic(LPCTSTR lpUnittype) } - if(!bPowerUp && i!=0 && (imghead.unknown==0 && !isTrue(g_data.sections["Debug"].values["IgnoreSHPImageHeadUnused"])) && bStructure) - { + if(!bPowerUp && i!=0 && (imghead.unknown==0 && !g_data.GetBool("Debug", "IgnoreSHPImageHeadUnused")) && bStructure) { if(lpT[i]) delete[] lpT[i]; lpT[i]=NULL; } @@ -2130,15 +2139,14 @@ BOOL CLoading::LoadUnitGraphic(LPCTSTR lpUnittype) int XMover, YMover; #ifdef RA2_MODE - XMover=atoi(g_data.sections["VehicleVoxelTurretsRA2"].values[(CString)lpUnittype+"X"]); - YMover=atoi(g_data.sections["VehicleVoxelTurretsRA2"].values[(CString)lpUnittype+"Y"]); + XMover=g_data.GetInteger("VehicleVoxelTurretsRA2", lpUnittype+"X"); + YMover=g_data.GetInteger("VehicleVoxelTurretsRA2", lpUnittype+"Y"); #else - XMover=atoi(g_data.sections["VehicleVoxelTurrets"].values[(CString)lpUnittype+"X"]); - YMover=atoi(g_data.sections["VehicleVoxelTurrets"].values[(CString)lpUnittype+"Y"]); + XMover=g_data.GetInteger("VehicleVoxelTurrets", lpUnittype+"X"); + YMover=g_data.GetInteger("VehicleVoxelTurrets", lpUnittype+"Y"); #endif - if (artSection.values.find("TurretOffset") != art.sections[image].values.end()) - iTurretOffset = atoi(art.sections[image].values["TurretOffset"]); + iTurretOffset = art.GetInteger(image, "TurretOffset", iTurretOffset); int i; @@ -2172,8 +2180,7 @@ BOOL CLoading::LoadUnitGraphic(LPCTSTR lpUnittype) RECT lprB; int turret_x,turret_y,turret_x_zmax,turret_y_zmax,barrel_x,barrel_y; - if(isTrue(rules.sections[lpUnittype].values["Turret"])) - { + if(rules.GetBool( lpUnittype, "Turret")) { if(FSunPackLib::SetCurrentVXL(image+"tur.vxl", hMix)) { FSunPackLib::LoadVXLImage(*m_voxelNormalTables, lightDirection, rotation, turretModelOffset, turretColors, turretNormals, &turret_x,&turret_y, 0, &turret_x_zmax, &turret_y_zmax,-1,-1,&lprT); @@ -2207,7 +2214,7 @@ BOOL CLoading::LoadUnitGraphic(LPCTSTR lpUnittype) FSunPackLib::GetVXLSectionInfo(0, vnc); // we assume the normal class for all voxels sections and turrets or barrels is the same DDSURFACEDESC2 ddsd; - memset(&ddsd, 0, sizeof(DDSURFACEDESC2)); + ::memset(&ddsd, 0, sizeof(DDSURFACEDESC2)); ddsd.dwSize=sizeof(DDSURFACEDESC2); ddsd.dwFlags=DDSD_WIDTH | DDSD_HEIGHT; ddsd.dwWidth=r.right-r.left; @@ -2219,7 +2226,7 @@ BOOL CLoading::LoadUnitGraphic(LPCTSTR lpUnittype) if(turretColors.size()) { DDSURFACEDESC2 ddsdT; - memset(&ddsdT, 0, sizeof(DDSURFACEDESC2)); + ::memset(&ddsdT, 0, sizeof(DDSURFACEDESC2)); ddsdT.dwSize=sizeof(DDSURFACEDESC2); ddsdT.dwFlags=DDSD_WIDTH | DDSD_HEIGHT; ddsdT.dwWidth=lprT.right-lprT.left; @@ -2227,7 +2234,7 @@ BOOL CLoading::LoadUnitGraphic(LPCTSTR lpUnittype) //lpTurret->GetSurfaceDesc(&ddsdT); DDBLTFX fx; - memset(&fx, 0, sizeof(DDBLTFX)); + ::memset(&fx, 0, sizeof(DDBLTFX)); fx.dwSize=sizeof(DDBLTFX); @@ -2254,7 +2261,7 @@ BOOL CLoading::LoadUnitGraphic(LPCTSTR lpUnittype) if(barrelColors.size()) { DDSURFACEDESC2 ddsdB; - memset(&ddsdB, 0, sizeof(DDSURFACEDESC2)); + ::memset(&ddsdB, 0, sizeof(DDSURFACEDESC2)); ddsdB.dwSize=sizeof(DDSURFACEDESC2); ddsdB.dwFlags=DDSD_WIDTH | DDSD_HEIGHT; ddsdB.dwWidth=lprB.right-lprB.left; @@ -2262,7 +2269,7 @@ BOOL CLoading::LoadUnitGraphic(LPCTSTR lpUnittype) //lpBarrel->GetSurfaceDesc(&ddsdB); DDSURFACEDESC2 ddsdT; - memset(&ddsdT, 0, sizeof(DDSURFACEDESC2)); + ::memset(&ddsdT, 0, sizeof(DDSURFACEDESC2)); ddsdT.dwSize=sizeof(DDSURFACEDESC2); ddsdT.dwFlags=DDSD_WIDTH | DDSD_HEIGHT; @@ -2275,7 +2282,7 @@ BOOL CLoading::LoadUnitGraphic(LPCTSTR lpUnittype) DDBLTFX fx; - memset(&fx, 0, sizeof(DDBLTFX)); + ::memset(&fx, 0, sizeof(DDBLTFX)); fx.dwSize=sizeof(DDBLTFX); RECT srcRect, destRect; @@ -2303,7 +2310,7 @@ BOOL CLoading::LoadUnitGraphic(LPCTSTR lpUnittype) errstream << ddsd.dwWidth << " " << ddsd.dwHeight << "\n"; PICDATA p; p.pic = new(BYTE[colors.size()]); - memcpy(p.pic, colors.data(), colors.size()); + ::memcpy(p.pic, colors.data(), colors.size()); p.lighting = pLighting; p.normalClass = vnc; @@ -2351,7 +2358,7 @@ BOOL CLoading::LoadUnitGraphic(LPCTSTR lpUnittype) } void CLoading::LoadBuildingSubGraphic(const CString& subkey, const CIniFileSection& artSection, BOOL bAlwaysSetChar, char theat, HMIXFILE hShpMix, SHPHEADER& shp_h, BYTE*& shp) { - CString subname = artSection.GetValueByName(subkey); + CString subname = artSection.GetString(subkey); if (subname.GetLength() > 0) { auto res = FindUnitShp(subname, theat, artSection); @@ -2374,1212 +2381,6 @@ void CLoading::LoadBuildingSubGraphic(const CString& subkey, const CIniFileSecti } } } -#else // surfaces -BOOL CLoading::LoadUnitGraphic(LPCTSTR lpUnittype) -{ - last_succeeded_operation=10; - - CString _rules_image; // the image used - CString filename; // filename of the image - char theat=cur_theat; // standard theater char is t (Temperat). a is snow. - - BOOL bAlwaysSetChar; // second char is always theater, even if NewTheater not specified! - WORD wStep=1; // step is 1 for infantry, buildings, etc, and for shp vehicles it specifies the step rate between every direction - WORD wStartWalkFrame=0; // for examply cyborg reaper has another walk starting frame - int iTurretOffset=0; // used for centering y pos of turret (if existing) - BOOL bStructure=rules.sections["BuildingTypes"].FindValue(lpUnittype)>=0; // is this a structure? - - BOOL bPowerUp=rules.sections[lpUnittype].values["PowersUpBuilding"]!=""; - - HTSPALETTE hPalette; - if(theat=='T') hPalette=m_hPalIsoTemp; - if(theat=='A') hPalette=m_hPalIsoSnow; - if(theat=='U') hPalette=m_hPalIsoUrb; - - CIsoView& v=*((CFinalSunDlg*)theApp.m_pMainWnd)->m_view.m_isoview; - - _rules_image = lpUnittype; - if (rules.sections[lpUnittype].values.find("Image") != rules.sections[lpUnittype].values.end()) - _rules_image = rules.sections[lpUnittype].values["Image"]; - - CString _art_image = _rules_image; - if (art.sections[_rules_image].values.find("Image") != art.sections[_rules_image].values.end()) - { - if (!isTrue(g_data.sections["IgnoreArtImage"].values[_rules_image])) - _art_image = art.sections[_rules_image].values["Image"]; - } - - const CString& image = _art_image; - const auto& rulesSection = rules.sections[lpUnittype]; - const auto& artSection = art.sections[image]; - - if(!isTrue(art.sections[image].values["Voxel"])) // is it a shp graphic? - { - try - { - - filename=image+".shp"; - - - BYTE bTerrain=0; - - - - BOOL isNewTerrain=FALSE; - if(isTrue(art.sections[image].values["NewTheater"]))//&& isTrue(artSection.GetValueByName("TerrainPalette")))//(filename.GetAt(0)=='G' || filename.GetAt(0)=='N' || filename.GetAt(0)=='C') && filename.GetAt(1)=='A') - { - hPalette=m_hPalUnitTemp; - if(theat=='A') hPalette=m_hPalUnitSnow; - if(theat=='U') hPalette=m_hPalUnitUrb; - filename.SetAt(1, theat); - isNewTerrain=TRUE; - } - - - HMIXFILE hShpMix=FindFileInMix(filename, &bTerrain); - - BYTE bIgnoreTerrain=TRUE; - - if(hShpMix==NULL && isNewTerrain) - { - filename.SetAt(1, 'G'); - hShpMix=FindFileInMix(filename, &bTerrain); - if(hShpMix) theat='G'; - - } - - - - if(hShpMix==NULL && isNewTerrain) - { - filename.SetAt(1, 'A'); - hShpMix=FindFileInMix(filename, &bTerrain); - if(hShpMix) theat='A'; - } - - if(hShpMix==NULL && isNewTerrain) - { - filename.SetAt(1, 'T'); - hShpMix=FindFileInMix(filename, &bTerrain); - if(hShpMix){ - theat='T'; - hPalette=m_hIsoTemp; - } - } - - - if(isTrue(artSection.GetValueByName("TerrainPalette"))) - { - bIgnoreTerrain=FALSE; - - if(cur_theat=='T') - hPalette=m_hPalIsoTemp; - else if(cur_theat=='A') - hPalette=m_hPalIsoSnow; - else if (cur_theat=='U') - hPalette=m_hPalIsoUrb; - - - - } - - - - if(hShpMix==0) - { - filename=image; - filename+=".shp"; - hShpMix=FindFileInMix(filename, &bTerrain); - - - - if(hShpMix==NULL) - { - filename=image; - if(theat=='T') filename+=".tem"; - if(theat=='A') filename+=".sno"; - if(theat=='U') filename+=".urb"; - filename.MakeLower(); - hShpMix=FindFileInMix(filename, &bTerrain); - - if(hShpMix==NULL) - { - filename=image; - filename+=".tem"; - hShpMix=FindFileInMix(filename, &bTerrain); - if(hShpMix) - { - hPalette=m_hPalIsoTemp; - } - } - - if(hShpMix!=NULL) - { - - - - } - else - { - filename=image+".shp"; - - filename.SetAt(1, 'A'); - - hShpMix=FindFileInMix(filename); - - if(hShpMix!=NULL) - { - bAlwaysSetChar=TRUE; - } - else - { - filename.SetAt(1, 'A'); - hShpMix=FindFileInMix(filename); - - if(hShpMix!=NULL) - { - theat='A'; - bAlwaysSetChar=TRUE; - } - else - { - filename.SetAt(1, 'U'); - hShpMix=FindFileInMix(filename); - if(hShpMix) theat='U'; - else - { - filename.SetAt(1, 'T'); - hShpMix=FindFileInMix(filename); - if(hShpMix) theat='T'; - } - } - } - } - } - else - { - theat='T'; - } - - } - else - { - - // now we need to find out the palette - - if(isTrue(artSection.GetValueByName("TerrainPalette"))) // it´s a file in isotemp.mix/isosno.mix - { - - } - else // it´s a file in temperat.mix/snow.mix - { - if(cur_theat=='T') hPalette=m_hPalUnitTemp; - if(cur_theat=='A') hPalette=m_hPalUnitSnow; - if(cur_theat=='U') hPalette=m_hPalUnitUrb; - } - - } - - - - if(filename=="tibtre01.tem" || filename=="tibtre02.tem" || filename=="tibtre03.tem" || filename=="veinhole.tem") - { - hPalette=m_hPalUnitTemp; - } - - - SHPHEADER head; - CString bibname; - CString bibfilename; - CString activeanim_name; - CString activeanim_filename; - CString idleanim_name; - CString idleanim_filename; - CString activeanim2_name; - CString activeanim2_filename; - CString activeanim3_name; - CString activeanim3_filename; - CString superanim1_name,superanim1_filename; - CString superanim2_name,superanim2_filename; - CString superanim3_name,superanim3_filename; - CString superanim4_name,superanim4_filename; - CString specialanim1_name,specialanim1_filename; - CString specialanim2_name,specialanim2_filename; - CString specialanim3_name,specialanim3_filename; - CString specialanim4_name,specialanim4_filename; - - CString turretanim_name; - CString turretanim_filename; - LPDIRECTDRAWSURFACE4 bib=NULL; - LPDIRECTDRAWSURFACE4 activeanim=NULL; - LPDIRECTDRAWSURFACE4 idleanim=NULL; - LPDIRECTDRAWSURFACE4 activeanim2=NULL; - LPDIRECTDRAWSURFACE4 activeanim3=NULL; - LPDIRECTDRAWSURFACE4 superanim1=NULL; - LPDIRECTDRAWSURFACE4 superanim2=NULL; - LPDIRECTDRAWSURFACE4 superanim3=NULL; - LPDIRECTDRAWSURFACE4 superanim4=NULL; - LPDIRECTDRAWSURFACE4 specialanim1=NULL; - LPDIRECTDRAWSURFACE4 specialanim2=NULL; - LPDIRECTDRAWSURFACE4 specialanim3=NULL; - LPDIRECTDRAWSURFACE4 specialanim4=NULL; - LPDIRECTDRAWSURFACE4* lpT=NULL; - LPDIRECTDRAWSURFACE4 turrets[8] = { 0 }; - SHPIMAGEHEADER turretinfo[8]; - - if(hShpMix>0) - { - - - //errstream << (LPCTSTR)filename << " found " ; - //errstream.flush(); - - - if(rules.sections[lpUnittype].values["Bib"]!="no") // seems to be ignored by TS, art.ini overwrites??? - { - - bibname=art.sections[image].values["BibShape"]; - if(bibname.GetLength()>0) - { - bibfilename=bibname+".shp"; - - if(isTrue(art.sections[image].values["NewTheater"])) - bibfilename.SetAt(1, theat); - - if(bAlwaysSetChar) bibfilename.SetAt(1, theat); - - if(FSunPackLib::XCC_DoesFileExist(bibfilename, hShpMix)) - { - FSunPackLib::SetCurrentSHP(bibfilename, hShpMix); - FSunPackLib::LoadSHPImageInSurface(v.dd, hPalette, 0, 1, &bib); - - } - } - } - - activeanim_name=art.sections[image].values["ActiveAnim"]; - if(activeanim_name.GetLength()>0) - { - activeanim_filename=activeanim_name+".shp"; - - if(isTrue(art.sections[image].values["NewTheater"])) - activeanim_filename.SetAt(1, theat); - - if(bAlwaysSetChar) activeanim_filename.SetAt(1, theat); - - if(FSunPackLib::XCC_DoesFileExist(activeanim_filename, hShpMix)) - { - FSunPackLib::SetCurrentSHP(activeanim_filename, hShpMix); - - FSunPackLib::LoadSHPImageInSurface(v.dd, hPalette, 0, 1, &activeanim); - - - } - } - - idleanim_name=art.sections[image].values["IdleAnim"]; - if(idleanim_name.GetLength()>0) - { - idleanim_filename=idleanim_name+".shp"; - - if(isTrue(art.sections[image].values["NewTheater"])) - idleanim_filename.SetAt(1, theat); - - if(bAlwaysSetChar) idleanim_filename.SetAt(1, theat); - - if(FSunPackLib::XCC_DoesFileExist(idleanim_filename, hShpMix)) - { - FSunPackLib::SetCurrentSHP(idleanim_filename, hShpMix); - - FSunPackLib::LoadSHPImageInSurface(v.dd, hPalette, 0, 1, &idleanim); - } - } - - - activeanim2_name=art.sections[image].values["ActiveAnimTwo"]; - if(activeanim2_name.GetLength()>0) - { - activeanim2_filename=activeanim2_name+".shp"; - - if(isTrue(art.sections[image].values["NewTheater"])) - activeanim2_filename.SetAt(1, theat); - - if(bAlwaysSetChar) activeanim2_filename.SetAt(1, theat); - - if(FSunPackLib::XCC_DoesFileExist(activeanim2_filename, hShpMix)) - { - FSunPackLib::SetCurrentSHP(activeanim2_filename, hShpMix); - - FSunPackLib::LoadSHPImageInSurface(v.dd, hPalette, 0, 1, &activeanim2); - - } - } - - activeanim3_name=art.sections[image].values["ActiveAnimThree"]; - if(activeanim3_name.GetLength()>0) - { - activeanim3_filename=activeanim3_name+".shp"; - - if(isTrue(art.sections[image].values["NewTheater"])) - activeanim3_filename.SetAt(1, theat); - - if(bAlwaysSetChar) activeanim3_filename.SetAt(1, theat); - - if(FSunPackLib::XCC_DoesFileExist(activeanim3_filename, hShpMix)) - { - FSunPackLib::SetCurrentSHP(activeanim3_filename, hShpMix); - - FSunPackLib::LoadSHPImageInSurface(v.dd, hPalette, 0, 1, &activeanim3); - - } - } - - superanim1_name=art.sections[image].values["SuperAnim"]; - if(superanim1_name.GetLength()>0) - { - superanim1_filename=superanim1_name+".shp"; - - if(isTrue(art.sections[image].values["NewTheater"])) - superanim1_filename.SetAt(1, theat); - - if(bAlwaysSetChar) superanim1_filename.SetAt(1, theat); - - if(FSunPackLib::XCC_DoesFileExist(superanim1_filename, hShpMix)) - { - FSunPackLib::SetCurrentSHP(superanim1_filename, hShpMix); - FSunPackLib::LoadSHPImageInSurface(v.dd, hPalette, 0, 1, &superanim1); - } - } - - superanim2_name=art.sections[image].values["SuperAnimTwo"]; - if(superanim2_name.GetLength()>0) - { - superanim2_filename=superanim2_name+".shp"; - - if(isTrue(art.sections[image].values["NewTheater"])) - superanim2_filename.SetAt(1, theat); - - if(bAlwaysSetChar) superanim2_filename.SetAt(1, theat); - - if(FSunPackLib::XCC_DoesFileExist(superanim2_filename, hShpMix)) - { - FSunPackLib::SetCurrentSHP(superanim2_filename, hShpMix); - FSunPackLib::LoadSHPImageInSurface(v.dd, hPalette, 0, 1, &superanim2); - } - } - - superanim3_name=art.sections[image].values["SuperAnimThree"]; - if(superanim3_name.GetLength()>0) - { - superanim3_filename=superanim3_name+".shp"; - - if(isTrue(art.sections[image].values["NewTheater"])) - superanim3_filename.SetAt(1, theat); - - if(bAlwaysSetChar) superanim3_filename.SetAt(1, theat); - - if(FSunPackLib::XCC_DoesFileExist(superanim3_filename, hShpMix)) - { - FSunPackLib::SetCurrentSHP(superanim3_filename, hShpMix); - FSunPackLib::LoadSHPImageInSurface(v.dd, hPalette, 0, 1, &superanim3); - } - } - - superanim4_name=art.sections[image].values["SuperAnimFour"]; - if(superanim4_name.GetLength()>0) - { - superanim4_filename=superanim4_name+".shp"; - - if(isTrue(art.sections[image].values["NewTheater"])) - superanim4_filename.SetAt(1, theat); - - if(bAlwaysSetChar) superanim4_filename.SetAt(1, theat); - - if(FSunPackLib::XCC_DoesFileExist(superanim4_filename, hShpMix)) - { - FSunPackLib::SetCurrentSHP(superanim4_filename, hShpMix); - FSunPackLib::LoadSHPImageInSurface(v.dd, hPalette, 0, 1, &superanim4); - } - } - - specialanim1_name=art.sections[image].values["SpecialAnim"]; - if(specialanim1_name.GetLength()>0) - { - specialanim1_filename=specialanim1_name+".shp"; - - if(isTrue(art.sections[image].values["NewTheater"])) - specialanim1_filename.SetAt(1, theat); - - if(bAlwaysSetChar) specialanim1_filename.SetAt(1, theat); - - if(FSunPackLib::XCC_DoesFileExist(specialanim1_filename, hShpMix)) - { - FSunPackLib::SetCurrentSHP(specialanim1_filename, hShpMix); - FSunPackLib::LoadSHPImageInSurface(v.dd, hPalette, 0, 1, &specialanim1); - } - } - - specialanim2_name=art.sections[image].values["SpecialAnimTwo"]; - if(specialanim2_name.GetLength()>0) - { - specialanim2_filename=specialanim2_name+".shp"; - - if(isTrue(art.sections[image].values["NewTheater"])) - specialanim2_filename.SetAt(1, theat); - - if(bAlwaysSetChar) specialanim2_filename.SetAt(1, theat); - - if(FSunPackLib::XCC_DoesFileExist(specialanim2_filename, hShpMix)) - { - FSunPackLib::SetCurrentSHP(specialanim2_filename, hShpMix); - FSunPackLib::LoadSHPImageInSurface(v.dd, hPalette, 0, 1, &specialanim2); - } - } - - specialanim3_name=art.sections[image].values["SpecialAnimThree"]; - if(specialanim3_name.GetLength()>0) - { - specialanim3_filename=specialanim3_name+".shp"; - - if(isTrue(art.sections[image].values["NewTheater"])) - specialanim3_filename.SetAt(1, theat); - - if(bAlwaysSetChar) specialanim3_filename.SetAt(1, theat); - - if(FSunPackLib::XCC_DoesFileExist(specialanim3_filename, hShpMix)) - { - FSunPackLib::SetCurrentSHP(specialanim3_filename, hShpMix); - FSunPackLib::LoadSHPImageInSurface(v.dd, hPalette, 0, 1, &specialanim3); - } - } - - specialanim4_name=art.sections[image].values["SpecialAnimFour"]; - if(specialanim4_name.GetLength()>0) - { - specialanim4_filename=specialanim4_name+".shp"; - - if(isTrue(art.sections[image].values["NewTheater"])) - specialanim4_filename.SetAt(1, theat); - - if(bAlwaysSetChar) specialanim4_filename.SetAt(1, theat); - - if(FSunPackLib::XCC_DoesFileExist(specialanim4_filename, hShpMix)) - { - FSunPackLib::SetCurrentSHP(specialanim4_filename, hShpMix); - FSunPackLib::LoadSHPImageInSurface(v.dd, hPalette, 0, 1, &specialanim4); - } - } - - BOOL bVoxelTurret=FALSE; - - turretanim_name=rules.sections[image].values["TurretAnim"]; - if(bStructure && rules.sections[image].values["Turret"]=="yes" && turretanim_name.GetLength()>0 && rules.sections[image].values["TurretAnimIsVoxel"]!="true") - { - turretanim_filename=turretanim_name+".shp"; - if(art.sections[turretanim_name].values.find("Image")!=art.sections[turretanim_name].values.end()) turretanim_filename=art.sections[turretanim_name].values["Image"]+".shp"; - - if(isTrue(art.sections[image].values["NewTheater"])) - turretanim_filename.SetAt(1, theat); - - - FSunPackLib::SetCurrentSHP(turretanim_filename, hShpMix); - FSunPackLib::XCC_GetSHPHeader(&head); - - int iStartTurret=0; - const WORD wAnimCount=4; // anims between each "normal" direction, seems to be hardcoded - - int i; - - for(i=0;i<8;i++) - { - if(iStartTurret+i*wAnimCount0 && rules.sections[image].values["TurretAnimIsVoxel"]=="true") - { - turretanim_filename=turretanim_name+".vxl"; - if(art.sections[turretanim_name].values.find("Image")!=art.sections[turretanim_name].values.end()) turretanim_filename=art.sections[turretanim_name].values["Image"]+".vxl"; - - //if(isTrue(art.sections[image].values["NewTheater"])) - // turretanim_filename.SetAt(1, theat); - - HMIXFILE hVXL=FindFileInMix(turretanim_filename); - - if(hVXL) - { - bVoxelTurret=TRUE; - - if( - FSunPackLib::SetCurrentVXL(turretanim_filename, hVXL) - ) - { - int i; - - for(i=0;i<8;i++) - { - float r_x,r_y,r_z; - - - r_x=300; - r_y=0; - r_z=45*i+90; - - // convert - const double pi = 3.141592654; - r_x=r_x/180.0f*pi; - r_y=r_y/180.0f*pi; - r_z=r_z/180.0f*pi; - - int center_x, center_y; - if(! - FSunPackLib::LoadVXLImageInSurface(*m_voxelNormalTables, lightDirection, v.dd, 0, 1, r_x, r_y, r_z, &turrets[i], hPalette,¢er_x, ¢er_y,atoi(rules.sections[image].values["TurretAnimZAdjust"])) - ) - { - - } - else - { - DDSURFACEDESC2 ddsd; - memset(&ddsd, 0, sizeof(DDSURFACEDESC2)); - ddsd.dwSize=sizeof(DDSURFACEDESC2); - ddsd.dwFlags=DDSD_WIDTH | DDSD_HEIGHT; - turrets[i]->GetSurfaceDesc(&ddsd); - turretinfo[i].x=-center_x; - turretinfo[i].y=-center_y; - turretinfo[i].cx=ddsd.dwWidth; - turretinfo[i].cy=ddsd.dwHeight; - } - - } - } - } - } - - - if(art.sections[image].values.find("WalkFrames")!=art.sections[image].values.end()) - wStep=atoi(art.sections[image].values["WalkFrames"]); - if(art.sections[image].values.find("StartWalkFrame")!=art.sections[image].values.end()) - wStartWalkFrame=atoi(art.sections[image].values["StartWalkFrame"]); - if(art.sections[image].values.find("TurretOffset")!=art.sections[image].values.end()) - iTurretOffset=atoi(art.sections[image].values["TurretOffset"]); - - - if(art.sections[image].values["Palette"]=="lib") - hPalette=m_hPalLib; - - BOOL bSuccess=FSunPackLib::SetCurrentSHP(filename, hShpMix); - if( - !bSuccess - ) - { - filename=image+=".sno"; - if(cur_theat=='T' || cur_theat=='U') hPalette=m_hPalIsoTemp; - hShpMix=FindFileInMix(filename, &bTerrain); - bSuccess=FSunPackLib::SetCurrentSHP(filename, hShpMix); - - if(!bSuccess) - { - missingimages[lpUnittype]=TRUE; - } - } - - if(bSuccess) - { - - FSunPackLib::XCC_GetSHPHeader(&head); - int i; - int maxPics=head.c_images; - if(maxPics>8) maxPics=8; // we only need 8 pictures for every direction! - if(bStructure && !bPowerUp) maxPics=1; - if(bVoxelTurret) maxPics=8; - - - if(!bStructure && rules.sections[image].values["Turret"]=="yes") - { - int iStartTurret=wStartWalkFrame+8*wStep; - const WORD wAnimCount=4; // anims between each "normal" direction, seems to be hardcoded - - int i; - - for(i=0;i<8;i++) - { - if(!bStructure && iStartTurret+i*wAnimCountBlt(NULL, bib, NULL, DDBLT_KEYSRC | DDBLT_WAIT , &fx); - - imghead.cx=head.cx-imghead.x; // update size of main graphic - imghead.cy=head.cy-imghead.y; - - } - - if(activeanim!=NULL) - { - DDBLTFX fx; - - memset(&fx, 0, sizeof(DDBLTFX)); - fx.dwSize=sizeof(DDBLTFX); - - lpT[i]->Blt(NULL, activeanim, NULL, DDBLT_KEYSRC | DDBLT_WAIT , &fx); - - - } - - if(idleanim!=NULL) - { - DDBLTFX fx; - - memset(&fx, 0, sizeof(DDBLTFX)); - fx.dwSize=sizeof(DDBLTFX); - - lpT[i]->Blt(NULL, idleanim, NULL, DDBLT_KEYSRC | DDBLT_WAIT , &fx); - - - } - - if(activeanim2!=NULL) - { - DDBLTFX fx; - - memset(&fx, 0, sizeof(DDBLTFX)); - fx.dwSize=sizeof(DDBLTFX); - - lpT[i]->Blt(NULL, activeanim2, NULL, DDBLT_KEYSRC | DDBLT_WAIT , &fx); - - - } - - if(activeanim3!=NULL) - { - DDBLTFX fx; - - memset(&fx, 0, sizeof(DDBLTFX)); - fx.dwSize=sizeof(DDBLTFX); - - lpT[i]->Blt(NULL, activeanim3, NULL, DDBLT_KEYSRC | DDBLT_WAIT , &fx); - - - } - - if(superanim1!=NULL) - { - DDBLTFX fx; - - memset(&fx, 0, sizeof(DDBLTFX)); - fx.dwSize=sizeof(DDBLTFX); - - lpT[i]->Blt(NULL, superanim1, NULL, DDBLT_KEYSRC | DDBLT_WAIT , &fx); - - - } - - if(superanim2!=NULL) - { - DDBLTFX fx; - - memset(&fx, 0, sizeof(DDBLTFX)); - fx.dwSize=sizeof(DDBLTFX); - - lpT[i]->Blt(NULL, superanim2, NULL, DDBLT_KEYSRC | DDBLT_WAIT , &fx); - - - } - - if(superanim3!=NULL) - { - DDBLTFX fx; - - memset(&fx, 0, sizeof(DDBLTFX)); - fx.dwSize=sizeof(DDBLTFX); - - lpT[i]->Blt(NULL, superanim3, NULL, DDBLT_KEYSRC | DDBLT_WAIT , &fx); - - - } - - if(superanim4!=NULL) - { - DDBLTFX fx; - - memset(&fx, 0, sizeof(DDBLTFX)); - fx.dwSize=sizeof(DDBLTFX); - - lpT[i]->Blt(NULL, superanim4, NULL, DDBLT_KEYSRC | DDBLT_WAIT , &fx); - - - } - - if(specialanim1!=NULL) - { - DDBLTFX fx; - - memset(&fx, 0, sizeof(DDBLTFX)); - fx.dwSize=sizeof(DDBLTFX); - - lpT[i]->Blt(NULL, specialanim1, NULL, DDBLT_KEYSRC | DDBLT_WAIT , &fx); - - - } - - if(specialanim2!=NULL) - { - DDBLTFX fx; - - memset(&fx, 0, sizeof(DDBLTFX)); - fx.dwSize=sizeof(DDBLTFX); - - lpT[i]->Blt(NULL, specialanim2, NULL, DDBLT_KEYSRC | DDBLT_WAIT , &fx); - - - } - - if(specialanim3!=NULL) - { - DDBLTFX fx; - - memset(&fx, 0, sizeof(DDBLTFX)); - fx.dwSize=sizeof(DDBLTFX); - - lpT[i]->Blt(NULL, specialanim3, NULL, DDBLT_KEYSRC | DDBLT_WAIT , &fx); - - - } - - if(specialanim4!=NULL) - { - DDBLTFX fx; - - memset(&fx, 0, sizeof(DDBLTFX)); - fx.dwSize=sizeof(DDBLTFX); - - lpT[i]->Blt(NULL, specialanim4, NULL, DDBLT_KEYSRC | DDBLT_WAIT , &fx); - - - } - - - - if(turrets[i]!=NULL) - { - DDBLTFX fx; - int iMove=0; - - DDSURFACEDESC2 ddsd; - memset(&ddsd, 0, sizeof(DDSURFACEDESC2)); - ddsd.dwSize=sizeof(DDSURFACEDESC2); - ddsd.dwFlags=DDSD_WIDTH | DDSD_HEIGHT; - turrets[i]->GetSurfaceDesc(&ddsd); - - - memset(&fx, 0, sizeof(DDBLTFX)); - fx.dwSize=sizeof(DDBLTFX); - - RECT srcRect, destRect; - srcRect.left=0; - srcRect.right=ddsd.dwWidth; - destRect.left=(head.cx-ddsd.dwWidth)/2; - destRect.right=head.cx-destRect.left; - - if(iMove<0) - { - srcRect.top=-iMove; - srcRect.bottom=ddsd.dwHeight; - destRect.top=0; - destRect.bottom=head.cy+iMove-(head.cy-ddsd.dwHeight); - } - else - { - int mx=imghead.x/2+imghead.cx/2+(-turretinfo[i].x/2-turretinfo[i].cx)+ atoi(rules.sections[image].values["TurretAnimX"]); - int my=imghead.y/2+imghead.cy/2+(-turretinfo[i].y/2-turretinfo[i].cy) + atoi(rules.sections[image].values["TurretAnimY"]);//+atoi(rules.sections[image].values["TurretAnimZAdjust"]); - - if(ddsd.dwWidth!=head.cx || ddsd.dwHeight!=head.cy) - { - // voxel turret - //mx=head.cx/2-ddsd.dwWidth/2;//+atoi(rules.sections[image].values["TurretAnimX"]); - //my=head.cy/2-ddsd.dwHeight/2+atoi(rules.sections[image].values["TurretAnimY"])+atoi(rules.sections[image].values["TurretAnimZAdjust"])/2; - mx=imghead.x+imghead.cx/2+turretinfo[i].x+atoi(rules.sections[image].values["TurretAnimX"]); - my=imghead.y+imghead.cy/2+turretinfo[i].y+atoi(rules.sections[image].values["TurretAnimY"]);//+atoi(rules.sections[image].values["TurretAnimZAdjust"])/2; - - errstream << turretinfo[i].x << " y:" << turretinfo[i].y << " mx:" << mx << " my:" << my << endl; - errstream.flush(); - - int XMover, YMover; -#ifdef RA2_MODE - XMover=atoi(g_data.sections["BuildingVoxelTurretsRA2"].values[(CString)lpUnittype+"X"]); - YMover=atoi(g_data.sections["BuildingVoxelTurretsRA2"].values[(CString)lpUnittype+"Y"]); -#else - XMover=atoi(g_data.sections["BuildingVoxelTurrets"].values[(CString)lpUnittype+"X"]); - YMover=atoi(g_data.sections["BuildingVoxelTurrets"].values[(CString)lpUnittype+"Y"]); -#endif - - mx+=XMover; - my+=YMover; - - srcRect.top=0; - srcRect.left=0; - srcRect.right=ddsd.dwWidth; - srcRect.bottom=ddsd.dwHeight; - destRect.top=my; - destRect.left=mx; - destRect.right=destRect.left+ddsd.dwWidth; - destRect.bottom=destRect.top+ddsd.dwHeight; - if(destRect.top<0) - { - int old=destRect.top; - destRect.top=0; - srcRect.top-=old-destRect.top; - - } - if(destRect.right>=head.cx) - { - int old=destRect.right; - destRect.right=head.cx; - srcRect.right-=old-destRect.right; - } - if(destRect.bottom>=head.cy) - { - int old=destRect.bottom; - destRect.bottom=head.cy; - srcRect.bottom-=old-destRect.bottom; - } - } - else - { - - if(mx<0)mx=0; - if(my<0)my=0; - srcRect.top=0; - srcRect.right=ddsd.dwWidth-mx; - srcRect.bottom=ddsd.dwHeight-my; - destRect.top=my; - destRect.left=mx+(head.cx-ddsd.dwWidth)/2; - destRect.right=destRect.left+ddsd.dwWidth;; - destRect.bottom=destRect.top+ddsd.dwHeight; - } - } - - - - - if(lpT[i]->Blt(&destRect, turrets[i], &srcRect, DDBLT_KEYSRC | DDBLT_WAIT, &fx)!=DD_OK) - { - - errstream << "vxl turret: " << i << " size: " << ddsd.dwWidth << " " << ddsd.dwHeight << " failed" << endl; - errstream.flush(); - //exit(-99); - } - - - } - - if(!bPowerUp && i!=0 && imghead.unknown==0 && bStructure) - { - if(lpT[i]) lpT[i]->Release(); - } - else - { - char ic[50]; - itoa(i, ic, 10); - - PICDATA p; - p.pic=lpT[i]; - p.x=imghead.x; - p.y=imghead.y; - p.wHeight=imghead.cy; - p.wWidth=imghead.cx; - p.wMaxWidth=head.cx; - p.wMaxHeight=head.cy; - p.bType=PICDATA_TYPE_SHP; - p.bTerrain=bTerrain; - if(bIgnoreTerrain) p.bTerrain=0; - - - pics[image+ic]=p; - - //errstream << " --> finished as " << (LPCSTR)(image+ic) << endl; - //errstream.flush(); - } - - - } - - delete[] lpT; - - - if(bib) bib->Release(); - if(activeanim)activeanim->Release(); - if(idleanim)idleanim->Release(); - if(activeanim2)activeanim2->Release(); - if(activeanim3)activeanim3->Release(); - if(superanim1)superanim1->Release(); - if(superanim2)superanim2->Release(); - if(superanim3)superanim3->Release(); - if(superanim4)superanim4->Release(); - if(specialanim1)specialanim1->Release(); - if(specialanim2)specialanim2->Release(); - if(specialanim3)specialanim3->Release(); - if(specialanim4)specialanim4->Release(); - - for(i=0;i<8;i++) - if(turrets[i])turrets[i]->Release(); - - } - - //errstream << " --> Finished" << endl; - //errstream.flush(); - } - - else - { - errstream << "File in theater " << cur_theat << " not found: " << (LPCTSTR)filename << endl; - errstream.flush(); - - missingimages[lpUnittype]=TRUE; - } - - } - catch(...) - { - errstream << " exception " << endl; - errstream.flush(); - } - - - } - else - { - filename=image+".vxl"; - - HMIXFILE hMix=FindFileInMix(filename); - if(hMix==FALSE) - { - missingimages[lpUnittype]=TRUE; - return FALSE; - } - - - int i; - - try - { - - for(i=0;i<8;i++) - { - float r_x,r_y,r_z; - - - r_x=300; - r_y=0; - r_z=45*i+90; - - // convert - const double pi = 3.141592654; - r_x=r_x/180.0f*pi; - r_y=r_y/180.0f*pi; - r_z=r_z/180.0f*pi; - - - - LPDIRECTDRAWSURFACE4 lpT;//=new(LPDIRECTDRAWSURFACE4[1]); - LPDIRECTDRAWSURFACE4 lpTurret=NULL; - LPDIRECTDRAWSURFACE4 lpBarrel=NULL; - int turret_x,turret_y,turret_x_zmax,turret_y_zmax,barrel_x,barrel_y; - - if(isTrue(rules.sections[lpUnittype].values["Turret"])) - { - if(FSunPackLib::SetCurrentVXL(image+"tur.vxl", hMix)) - { - FSunPackLib::LoadVXLImageInSurface(*m_voxelNormalTables, lightDirection, v.dd, 0, 1, r_x, r_y, r_z, &lpTurret, m_hPalUnitTemp,&turret_x,&turret_y,0,&turret_x_zmax, &turret_y_zmax,-1,-1); - } - if(FSunPackLib::SetCurrentVXL(image+"barl.vxl", hMix)) - { - FSunPackLib::LoadVXLImageInSurface(*m_voxelNormalTables, lightDirection, v.dd, 0, 1, r_x, r_y, r_z, &lpBarrel, m_hPalUnitTemp,&barrel_x,&barrel_y,0,NULL,NULL,0,0); - } - } - - - if(!FSunPackLib::SetCurrentVXL(filename, hMix)) - { - return FALSE; - } - - - - int xcenter,ycenter,xcenter_zmax,ycenter_zmax; - - if(! - FSunPackLib::LoadVXLImageInSurface(*m_voxelNormalTables, lightDirection, v.dd, 0, 1, r_x, r_y, r_z, &lpT, m_hPalUnitTemp,&xcenter, &ycenter,0,&xcenter_zmax,&ycenter_zmax) - ) - { - return FALSE; - } - - DDSURFACEDESC2 ddsd; - memset(&ddsd, 0, sizeof(DDSURFACEDESC2)); - ddsd.dwSize=sizeof(DDSURFACEDESC2); - ddsd.dwFlags=DDSD_WIDTH | DDSD_HEIGHT; - lpT->GetSurfaceDesc(&ddsd); - - // turret - if(lpTurret) - { - DDSURFACEDESC2 ddsdT; - memset(&ddsdT, 0, sizeof(DDSURFACEDESC2)); - ddsdT.dwSize=sizeof(DDSURFACEDESC2); - ddsdT.dwFlags=DDSD_WIDTH | DDSD_HEIGHT; - lpTurret->GetSurfaceDesc(&ddsdT); - - DDBLTFX fx; - memset(&fx, 0, sizeof(DDBLTFX)); - fx.dwSize=sizeof(DDBLTFX); - - RECT srcRect, destRect; - srcRect.left=0; - srcRect.right=ddsdT.dwWidth; - destRect.left=xcenter_zmax-turret_x; - destRect.right=destRect.left+ddsdT.dwWidth; - srcRect.top=0; - srcRect.bottom=ddsdT.dwHeight; - destRect.top=ycenter_zmax-turret_y; - destRect.bottom=destRect.top+ddsdT.dwHeight; - - lpT->Blt(&destRect, lpTurret, &srcRect, DDBLT_KEYSRC | DDBLT_WAIT, &fx); - - } - - // barrel - if(lpBarrel) - { - DDSURFACEDESC2 ddsdB; - memset(&ddsdB, 0, sizeof(DDSURFACEDESC2)); - ddsdB.dwSize=sizeof(DDSURFACEDESC2); - ddsdB.dwFlags=DDSD_WIDTH | DDSD_HEIGHT; - lpBarrel->GetSurfaceDesc(&ddsdB); - - DDSURFACEDESC2 ddsdT; - memset(&ddsdT, 0, sizeof(DDSURFACEDESC2)); - ddsdT.dwSize=sizeof(DDSURFACEDESC2); - ddsdT.dwFlags=DDSD_WIDTH | DDSD_HEIGHT; - - if(lpTurret) lpTurret->GetSurfaceDesc(&ddsdT); - - - DDBLTFX fx; - memset(&fx, 0, sizeof(DDBLTFX)); - fx.dwSize=sizeof(DDBLTFX); - - RECT srcRect, destRect; - srcRect.left=0; - srcRect.right=ddsdB.dwWidth; - destRect.left=xcenter_zmax-barrel_x+(turret_x_zmax-turret_x); - destRect.right=destRect.left+ddsdB.dwWidth; - srcRect.top=0; - srcRect.bottom=ddsdB.dwHeight; - destRect.top=ycenter_zmax-barrel_y+(turret_y_zmax-turret_y); - destRect.bottom=destRect.top+ddsdB.dwHeight; - - lpT->Blt(&destRect, lpBarrel, &srcRect, DDBLT_KEYSRC | DDBLT_WAIT, &fx); - - } - - char ic[50]; - itoa(7-i, ic, 10); - - errstream << ddsd.dwWidth << " " << ddsd.dwHeight << "\n"; - PICDATA p; - p.pic=lpT; - p.x=-xcenter; - p.y=-ycenter; - p.wHeight=ddsd.dwHeight; - p.wWidth=ddsd.dwWidth; - p.wMaxWidth=ddsd.dwWidth; - p.wMaxHeight=ddsd.dwHeight; - p.bType=PICDATA_TYPE_VXL; - p.bTerrain=0; - - pics[image+ic]=p; - - errstream << "vxl saved as " << (LPCSTR)image << (LPCSTR)ic << endl; - errstream.flush(); - - if(lpBarrel) lpBarrel->Release(); - if(lpTurret) lpTurret->Release(); - - //delete[] lpT; - - } - } - catch(...) - { - - } - - } - - - - return FALSE; -} #endif @@ -4384,36 +3185,36 @@ void CLoading::InitTMPs(CProgressCtrl* prog) errstream.flush(); // we need to have that here, CMapData::UpdateIniFile() is too late for the shore hack - shoreset=atoi((*tiles).sections["General"].values["ShorePieces"]); - waterset=atoi((*tiles).sections["General"].values["WaterSet"]); + shoreset = tiles->GetInteger("General", "ShorePieces"); + waterset = tiles->GetInteger("General", "WaterSet"); - int i, tcount=0; + int i, tcount = 0; - for(i=0;i<10000;i++) - { + for (i = 0; i < 10000; i++) { CString tset; char c[50]; itoa(i, c, 10); int e; - for(e=0;e<4-strlen(c);e++) - tset+="0"; + for (e = 0; e < 4 - strlen(c); e++) { + tset += "0"; + } tset+=c; CString sec="TileSet"; sec+=tset; - if(tiles->sections.find(sec)==tiles->sections.end()) break; + auto const pSec = tiles->TryGetSection(sec); + if (!pSec) { + break; + } - for(e=0;esections[sec].values["TilesInSet"]);e++) - { + for (e = 0; e < pSec->GetInteger("TilesInSet"); e++) { tcount++; } - - } if(prog) prog->SetRange(0, tcount); @@ -4436,34 +3237,40 @@ void CLoading::InitTMPs(CProgressCtrl* prog) CString sec="TileSet"; sec+=tset; - if(tiles->sections.find(sec)==tiles->sections.end()) break; + auto const pSec = tiles->TryGetSection(sec); + if (!pSec) { + break; + } BOOL bTib, bMorph, bPlace, bMadness; bPlace=TRUE; bTib=FALSE; bMorph=FALSE; bMadness=FALSE; - tiles->sections[sec].values["AllowTiberium"].MakeLower(); - if(tiles->sections[sec].values["AllowTiberium"]=="true") - bTib=TRUE; - tiles->sections[sec].values["Morphable"].MakeLower(); - if(tiles->sections[sec].values["Morphable"]=="true") - bMorph=TRUE; - tiles->sections[sec].values["AllowToPlace"].MakeLower(); - if(tiles->sections[sec].values["AllowToPlace"]=="no") - bPlace=FALSE; - tiles->sections[sec].values["NonMarbleMadness"].MakeLower(); - if(tiles->sections[sec].values["NonMarbleMadness"].GetLength()>0) - bMadness=TRUE; - auto tilesetAnimSection = tiles->GetSection(tiles->sections[sec].GetValueByName("SetName")); + + if (pSec->GetBool("AllowTiberium")) { + bTib = TRUE; + } + + if (pSec->GetBool("Morphable")) { + bMorph = TRUE; + } + + if (!pSec->GetBool("AllowToPlace")) { + bPlace = FALSE; + } + + if (!pSec->GetString("NonMarbleMadness").IsEmpty()) { + bMadness = TRUE; + } + auto const tilesetAnimSection = tiles->TryGetSection(tiles->GetString(sec, "SetName")); tilesets_start[i]=tilecount; - for(e=0;esections[sec].values["TilesInSet"]);e++) - { + for (e = 0; e < tiles->GetInteger(sec, "TilesInSet"); e++) { std::string sId = std::format("{:02}", e + 1); - CString filename=tiles->sections[sec].values["FileName"]; + CString filename = tiles->GetString(sec, "FileName"); filename+=sId.c_str(); CString bas_f=filename; @@ -4521,10 +3328,10 @@ void CLoading::InitTMPs(CProgressCtrl* prog) if (tilesetAnimSection) { - auto anim = tilesetAnimSection->GetValueByName(std::format("Tile{}Anim", sId).c_str()); - auto offsetX = std::atoi(tilesetAnimSection->GetValueByName(std::format("Tile{}XOffset", sId).c_str())); - auto offsetY = std::atoi(tilesetAnimSection->GetValueByName(std::format("Tile{}YOffset", sId).c_str())); - auto attachesTo = std::atoi(tilesetAnimSection->GetValueByName(std::format("Tile{}AttachesTo", sId).c_str())); + auto anim = tilesetAnimSection->GetString(std::format("Tile{}Anim", sId).c_str()); + auto offsetX = tilesetAnimSection->GetInteger(std::format("Tile{}XOffset", sId).c_str()); + auto offsetY = tilesetAnimSection->GetInteger(std::format("Tile{}YOffset", sId).c_str()); + auto attachesTo = tilesetAnimSection->GetInteger(std::format("Tile{}AttachesTo", sId).c_str()); auto animFileName = anim + suffix; HMIXFILE hAnimMix = FindFileInMix(animFileName); if (hAnimMix) @@ -4580,8 +3387,7 @@ void CLoading::InitTMPs(CProgressCtrl* prog) } tilecount=0; - for(i=0;i<10000;i++) - { + for (i = 0; i < 10000; i++) { CString tset; char c[50]; itoa(i, c, 10); @@ -4592,25 +3398,22 @@ void CLoading::InitTMPs(CProgressCtrl* prog) CString sec="TileSet"; sec+=tset; - if(tiles->sections.find(sec)==tiles->sections.end()) break; - - - int madnessid=atoi(tiles->sections[sec].values["MarbleMadness"]); - - for(e=0;esections[sec].values["TilesInSet"]);e++) - { - if(madnessid) - { - (*tiledata)[tilecount].wMarbleGround=tilesets_start[madnessid]+(tilecount-tilesets_start[i]); - } - else - (*tiledata)[tilecount].wMarbleGround=0xFFFF; - - tilecount++; - + auto const pSec = tiles->TryGetSection(sec); + if (!pSec) { + break; } + int madnessid= pSec->GetInteger("MarbleMadness"); + for (e = 0; e < pSec->GetInteger("TilesInSet"); e++) { + if(madnessid) { + (*tiledata)[tilecount].wMarbleGround=tilesets_start[madnessid]+(tilecount-tilesets_start[i]); + } + else { + (*tiledata)[tilecount].wMarbleGround = 0xFFFF; + } + tilecount++; + } } } @@ -4772,13 +3575,16 @@ BOOL CLoading::LoadTile(LPCSTR lpFilename, HMIXFILE hOwner, HTSPALETTE hPalette, #ifdef RA2_MODE section="ShoreTerrainRA2"; #endif - - if(g_data.sections[section].FindName(hack)>=0) - { - int t=atoi(g_data.sections[section].values[hack]); - if(t) td->tiles[i].bHackedTerrainType=TERRAINTYPE_WATER; - else - td->tiles[i].bHackedTerrainType=0xe; + auto const& sec = g_data.GetSection(section); + auto const hackValIdx = sec.FindIndex(hack); + if (hackValIdx >= 0) { + int t = atoi(sec.Nth(hackValIdx).second); + if (t) { + td->tiles[i].bHackedTerrainType = TERRAINTYPE_WATER; + } + else { + td->tiles[i].bHackedTerrainType = 0xe; + } } } if((*tiledata)[dwID].wTileSet==waterset) (*tiledata)[dwID].tiles[i].bHackedTerrainType=TERRAINTYPE_WATER; @@ -4812,184 +3618,6 @@ BOOL CLoading::LoadTile(LPCSTR lpFilename, HMIXFILE hOwner, HTSPALETTE hPalette, - return TRUE; - - -} -#else // now standard version, with surfaces -BOOL CLoading::LoadTile(LPCSTR lpFilename, HMIXFILE hOwner, HTSPALETTE hPalette, DWORD dwID, BOOL bReplacement) -{ - last_succeeded_operation=12; - - //errstream << "Loading " << lpFilename << " owned by " << hOwner << ", palette " << hPalette ; - //errstream << lpFilename << endl; - //errstream.flush(); - - CIsoView& v=*((CFinalSunDlg*)theApp.m_pMainWnd)->m_view.m_isoview; - - - //DeleteFile((CString)AppPath+(CString)"\\TmpTmp.tmp"); - //FSunPackLib::XCC_ExtractFile(lpFilename, (CString)AppPath+(CString)"\\TmpTmp.tmp" /*lpFilename*//*, hOwner); - - int tileCount; - try{ - if(FSunPackLib::XCC_DoesFileExist(lpFilename, hOwner)) - //if(DoesFileExist((CString)AppPath+(CString)"\\TmpTmp.tmp")) - { - //if( - FSunPackLib::SetCurrentTMP(lpFilename, hOwner); - //) - { - - //FSunPackLib::SetCurrentTMP((CString)AppPath+"\\TmpTmp.tmp"/* lpFilename*//*, NULL/*hOwner*//*); - int tileWidth, tileHeight; - RECT rect; - FSunPackLib::XCC_GetTMPInfo(&rect, &tileCount, &tileWidth, &tileHeight); - - - LPDIRECTDRAWSURFACE4* pics=new(LPDIRECTDRAWSURFACE4[tileCount]); - if(FSunPackLib::LoadTMPImageInSurface(v.dd,0, tileCount, pics, hPalette)) - //if(FSunPackLib::LoadTMPImageInSurface(v.dd,lpFilename, 0, tileCount, pics, hPalette, hOwner)) - { - TILEDATA* td; - if(!bReplacement) td=&(*tiledata)[dwID]; - else - { - - TILEDATA* lpTmp=NULL; - if((*tiledata)[dwID].bReplacementCount) - { - lpTmp=new(TILEDATA[(*tiledata)[dwID].bReplacementCount]); - memcpy(lpTmp, (*tiledata)[dwID].lpReplacements, sizeof(TILEDATA)* (*tiledata)[dwID].bReplacementCount); - } - - (*tiledata)[dwID].lpReplacements=new(TILEDATA[(*tiledata)[dwID].bReplacementCount+1]); - - if((*tiledata)[dwID].bReplacementCount) - { - memcpy((*tiledata)[dwID].lpReplacements, lpTmp, sizeof(TILEDATA)*(*tiledata)[dwID].bReplacementCount); - delete[] lpTmp; - } - - td=&(*tiledata)[dwID].lpReplacements[(*tiledata)[dwID].bReplacementCount]; - (*tiledata)[dwID].bReplacementCount++; - } - - - td->tiles=new(SUBTILE[tileCount]); - td->wTileCount=tileCount; - td->cx=tileWidth; - td->cy=tileHeight; - td->rect=rect; - - int i; - for(i=0;itiles[i].rgbLeft, &td->tiles[i].rgbRight); - td->tiles[i].pic=pics[i]; - td->tiles[i].sX=p.x; - td->tiles[i].sY=p.y; - td->tiles[i].wWidth=cx; - td->tiles[i].wHeight=cy; - td->tiles[i].bZHeight=height; - td->tiles[i].bTerrainType=terraintype; - td->tiles[i].bHackedTerrainType=terraintype; - td->tiles[i].bDirection=direction; - - if(terraintype==0xa) - { -#ifdef RA2_MODE - td->tiles[i].bHackedTerrainType=TERRAINTYPE_WATER; -#else - td->tiles[i].bHackedTerrainType=TERRAINTYPE_WATER; -#endif - } - if(terraintype==TERRAINTYPE_ROUGH) td->tiles[i].bHackedTerrainType=TERRAINTYPE_GROUND; - - //if((*tiledata)[dwID].wTileSet==waterset) (*tiledata)[dwID].tiles[i].bHackedTerrainType=TERRAINTYPE_WATER; - - // shore hack: check fsdata.ini for new shore terrain - if(td->wTileSet==shoreset) - { - int h; - for(h=0;h<(*tiledata_count);h++) - { - if((*tiledata)[h].wTileSet==shoreset) break; - } - - int pos=dwID-h; - char c[50]; - itoa(pos,c,10); - CString hack=c; - hack+="_"; - itoa(i, c, 10); - hack+=c;/* - hack+="_"; - itoa(i/tileWidth, c, 10); - hack+=c;*/ - - CString section="ShoreTerrainTS"; -#ifdef RA2_MODE - section="ShoreTerrainRA2"; -#endif - - if(g_data.sections[section].FindName(hack)>=0) - { - int t=atoi(g_data.sections[section].values[hack]); - if(t) td->tiles[i].bHackedTerrainType=TERRAINTYPE_WATER; - else - td->tiles[i].bHackedTerrainType=0xe; - } - } - if((*tiledata)[dwID].wTileSet==waterset) (*tiledata)[dwID].tiles[i].bHackedTerrainType=TERRAINTYPE_WATER; - } - else - { - td->tiles[i].pic=NULL; - td->tiles[i].sX=0; - td->tiles[i].sY=0; - td->tiles[i].wWidth=0; - td->tiles[i].wHeight=0; - td->tiles[i].bZHeight=0; - td->tiles[i].bTerrainType=0; - td->tiles[i].bDirection=0; - } - } - } - - if(tileCount>0) delete[] pics; - } - } - else - { - //errstream << " not found" << endl; - return FALSE; - } - } - catch(...) - { - - } - - if((*tiledata)[dwID].wTileCount==0 || (*tiledata)[dwID].tiles[0].pic==NULL) - { - //errstream << " failed" << endl; - //errstream.flush(); - - return FALSE; - } - else - { - //errstream << " succeeded" << endl; - //errstream.flush(); - } - return TRUE; @@ -4997,7 +3625,7 @@ BOOL CLoading::LoadTile(LPCSTR lpFilename, HMIXFILE hOwner, HTSPALETTE hPalette, #endif #ifdef NOSURFACES_OBJECTS // palettized -void CLoading::LoadOverlayGraphic(LPCTSTR lpOvrlName_, int iOvrlNum) +void CLoading::LoadOverlayGraphic(const CString& lpOvrlName_, int iOvrlNum) { last_succeeded_operation=11; @@ -5055,8 +3683,8 @@ void CLoading::LoadOverlayGraphic(LPCTSTR lpOvrlName_, int iOvrlNum) } HTSPALETTE forcedPalette = 0; - const auto& isoPalettePrefixes = g_data.sections["ForceOvrlIsoPalettePrefix"]; - const auto& unitPalettePrefixes = g_data.sections["ForceOvrlUnitPalettePrefix"]; + const auto& isoPalettePrefixes = g_data["ForceOvrlIsoPalettePrefix"]; + const auto& unitPalettePrefixes = g_data["ForceOvrlUnitPalettePrefix"]; const CString sOvrlName(lpOvrlName_); if (unitPalettePrefixes.end() != std::find_if(unitPalettePrefixes.begin(), unitPalettePrefixes.end(), [&sOvrlName](const auto& pair) {return sOvrlName.Find(pair.second) == 0;})) { @@ -5070,54 +3698,56 @@ void CLoading::LoadOverlayGraphic(LPCTSTR lpOvrlName_, int iOvrlNum) HMIXFILE hMix; CString lpOvrlName = lpOvrlName_; - if(lpOvrlName.Find(' ')>=0) lpOvrlName = lpOvrlName.Left(lpOvrlName.Find(' ')); + if (lpOvrlName.Find(' ') >= 0) { + lpOvrlName = lpOvrlName.Left(lpOvrlName.Find(' ')); + } //if(strchr(lpOvrlName, ' ')!=NULL) strchr(lpOvrlName, ' ')[0]=0; //if(lpOvrlName - CString isveinhole_t=rules.sections[lpOvrlName].values["IsVeinholeMonster"]; - CString istiberium_t=rules.sections[lpOvrlName].values["Tiberium"]; - CString isveins_t=rules.sections[lpOvrlName].values["IsVeins"]; - isveinhole_t.MakeLower(); - istiberium_t.MakeLower(); - isveins_t.MakeLower(); - BOOL isveinhole=FALSE, istiberium=FALSE, isveins=FALSE; - if(isTrue(isveinhole_t)) isveinhole=TRUE; - if(isTrue(istiberium_t)) istiberium=TRUE; - if(isTrue(isveins_t)) isveins=TRUE; - - + auto const isveinhole = rules.GetBool(lpOvrlName, "IsVeinholeMonster"); + auto const istiberium = rules.GetBool(lpOvrlName, "Tiberium"); + auto const isveins = rules.GetBool(lpOvrlName, "IsVeins"); - - image=lpOvrlName; - if(rules.sections[lpOvrlName].values.find("Image")!=rules.sections[lpOvrlName].values.end()) - image=rules.sections[lpOvrlName].values["Image"]; + auto const imageID = rules.GetString(lpOvrlName, "Image"); + if (!imageID.IsEmpty()) { + image= imageID; + } TruncSpace(image); CString imagerules=image; - if(art.sections[image].values.find("Image")!=art.sections[image].values.end()) - image=art.sections[image].values["Image"]; + auto const& imageID = art.GetString(image, "Image"); + if (!imageID.IsEmpty()) { + image = imageID; + } TruncSpace(image); - if(cur_theat=='T') filename=image+".tem"; - if(cur_theat=='A') filename=image+".sno"; - if(cur_theat=='U') filename=image+".urb"; - if(cur_theat=='N') filename=image+".ubn"; - if(cur_theat=='L') filename=image+".lun"; - if(cur_theat=='D') filename=image+".des"; + if (cur_theat == 'T') { + filename = image + ".tem"; + } else if (cur_theat == 'A') { + filename = image + ".sno"; + } else if (cur_theat == 'U') { + filename = image + ".urb"; + } else if (cur_theat == 'N') { + filename = image + ".ubn"; + } else if (cur_theat == 'L') { + filename = image + ".lun"; + } else if (cur_theat == 'D') { + filename = image + ".des"; + } hMix=FindFileInMix(filename); - const auto& artSection = art.sections[image]; + const auto& artSection = art[image]; - if(hMix==NULL) - { + if (hMix == NULL) { filename=image+".shp"; - if(isTrue(artSection.GetValueByName("NewTheater"))) + if (artSection.GetBool("NewTheater")) { filename.SetAt(1, theat); + } if(cur_theat=='U' && m_hPalUnitUrb) hPalette=m_hPalUnitUrb; if(cur_theat=='T') hPalette=m_hPalUnitTemp; @@ -5297,15 +3927,15 @@ void CLoading::LoadOverlayGraphic(LPCTSTR lpOvrlName_, int iOvrlNum) FSunPackLib::XCC_GetSHPImageHeader(i, &imghead); // MW: fixed april 20th, 2002 - if(imghead.unknown==0 && !isTrue(g_data.sections["Debug"].values["IgnoreSHPImageHeadUnused"])) // is it a shadow or not used image? - if(lpT[i]) - { + // is it a shadow or not used image? + if (imghead.unknown == 0 && !g_data.GetBool("Debug", "IgnoreSHPImageHeadUnused")) { + if (lpT[i]) { delete[] lpT[i]; - lpT[i]=NULL; + lpT[i] = NULL; } + } - if(/*imghead.unknown &&*/ lpT[i]) - { + if(/*imghead.unknown &&*/ lpT[i]) { char ic[50]; itoa(i, ic, 10); @@ -5670,12 +4300,12 @@ void CLoading::CalcPicCount() m_bmp_count=m_pic_count; - if(!theApp.m_Options.bDoNotLoadVehicleGraphics) m_pic_count+=rules.sections["VehicleTypes"].values.size(); - if(!theApp.m_Options.bDoNotLoadOverlayGraphics) m_pic_count+=rules.sections["OverlayTypes"].values.size(); - if(!theApp.m_Options.bDoNotLoadInfantryGraphics) m_pic_count+=rules.sections["InfantryTypes"].values.size(); - if(!theApp.m_Options.bDoNotLoadBuildingGraphics) m_pic_count+=rules.sections["BuildingTypes"].values.size(); - if(!theApp.m_Options.bDoNotLoadAircraftGraphics) m_pic_count+=rules.sections["AircraftTypes"].values.size(); - if(!theApp.m_Options.bDoNotLoadTreeGraphics) m_pic_count+=rules.sections["TerrainTypes"].values.size(); + if(!theApp.m_Options.bDoNotLoadVehicleGraphics) m_pic_count+=rules["VehicleTypes"].Size(); + if(!theApp.m_Options.bDoNotLoadOverlayGraphics) m_pic_count+=rules["OverlayTypes"].Size(); + if(!theApp.m_Options.bDoNotLoadInfantryGraphics) m_pic_count+=rules["InfantryTypes"].Size(); + if(!theApp.m_Options.bDoNotLoadBuildingGraphics) m_pic_count+=rules["BuildingTypes"].Size(); + if(!theApp.m_Options.bDoNotLoadAircraftGraphics) m_pic_count+=rules["AircraftTypes"].Size(); + if(!theApp.m_Options.bDoNotLoadTreeGraphics) m_pic_count+=rules["TerrainTypes"].Size(); int i; /* @@ -6174,36 +4804,37 @@ void CLoading::PostNcDestroy() void CLoading::PrepareHouses() { - int i; - int p=0 ; - for(i=0;i0) - { - sides[p].name=GetParam(*rules.sections["Sides"].GetValue(i), t); - sides[p].orig_n=rules.sections["Sides"].GetValueOrigPos(i); // mw fix instead of =i + int p = 0; + auto const& sideSec = rules["Sides"]; + for (auto i = 0; i < sideSec.Size(); i++) { + int t = 0; + auto const& sideParams = sideSec.Nth(i).second; + for (;;) { + auto const paramN = GetParam(sideParams, t); + if (paramN.IsEmpty()) { + break; + } + sides[p].name = paramN; + sides[p].orig_n = i; // mw fix instead of =i t++; p++; } } - for(i=0;i AllStrings; +extern TranslationMap AllStrings; void CLoading::LoadStrings() { last_succeeded_operation=9; @@ -6415,34 +5046,27 @@ void CLoading::LoadStrings() - for(i=0;iFindName("UIName")>=0) - { - int e; - - if(strings.find(rules.GetSection(i)->values["UIName"])!=strings.end()) - { - //MessageBox(strings[rules.GetSection(i)->values["UIName"]].cString); - if(!strings[rules.GetSection(i)->values["UIName"]].bUsedDefault) - { - //CCStrings[*rules.GetSectionName(i)].cString=strings[rules.GetSection(i)->values["UIName"]].cString; //.SetString(strings[rules.GetSection(i)->values["UIName"]].wString, strings[rules.GetSection(i)->values["UIName"]].len); - CCStrings[*rules.GetSectionName(i)].SetString(strings[rules.GetSection(i)->values["UIName"]].wString, strings[rules.GetSection(i)->values["UIName"]].len); - } - else - { - CCStrings[*rules.GetSectionName(i)].SetString(strings[rules.GetSection(i)->values["UIName"]].wString, strings[rules.GetSection(i)->values["UIName"]].len); - CCStrings[*rules.GetSectionName(i)].cString=rules.GetSection(i)->GetValueByName("Name"); - } - } - else - { - //MessageBox((LPSTR)(LPCSTR)rules.GetSection(i)->values["Name"], *rules.GetSectionName(i)); - CCStrings[*rules.GetSectionName(i)].SetString((LPSTR)(LPCSTR)rules.GetSection(i)->GetValueByName("Name")); - } + for (auto const& [secName, sec] : rules) { + auto const& uiNameLabel = sec.GetString("UIName"); + if (uiNameLabel.IsEmpty()) { + CCStrings[secName].SetString(sec.GetString("Name")); + continue; } - else CCStrings[*rules.GetSectionName(i)].SetString((LPSTR)(LPCSTR)rules.GetSection(i)->GetValueByName("Name")); - + auto const found = strings.find(uiNameLabel); + // no record + if (found == strings.end()) { + //MessageBox((LPSTR)(LPCSTR)rules.GetSection(i)->values["Name"], secName); + CCStrings[secName].SetString(sec.GetString("Name")); + continue; + } + //MessageBox(strings[uiNameLabel].cString); + if (!found->second.bUsedDefault) { + //CCStrings[secName].cString=strings[uiNameLabel].cString; //.SetString(strings[uiNameLabel].wString, strings[uiNameLabel].len); + CCStrings[secName].SetString(strings[uiNameLabel].wString, strings[uiNameLabel].len); + continue; + } + CCStrings[secName].SetString(strings[uiNameLabel].wString, strings[uiNameLabel].len); + CCStrings[secName].cString = sec.GetString("Name"); } @@ -6450,7 +5074,7 @@ void CLoading::LoadStrings() int i; for(i=0;iFindName("Name")>=0) + if(rules.GetSection(i)->FindIndex("Name")>=0) { //CCStrings[*rules.GetSectionName(i)].cString=rules.GetSection(i)->values["Name"]; //CCStrings[*rules.GetSectionName(i)].SetString=rul @@ -6464,42 +5088,40 @@ void CLoading::LoadStrings() void CLoading::HackRules() { - if(editor_mode==ra2_mode) - { - int i; - int max_c=0; - for(i=0;imax_c) max_c=p; + if (editor_mode == ra2_mode) { + + auto const& gateOne = rules.GetString("General", "GDIGateOne"); + if (!gateOne.IsEmpty()) { + auto const pSec = rules.TryGetSection("BuildingTypes"); + ASSERT(pSec != nullptr); + if (!pSec->HasValue(gateOne)) { + pSec->Insert(gateOne, gateOne); + } } - char c[50]; - itoa(max_c+1,c,10); - - rules.sections["BuildingTypes"].values[c]=rules.sections["General"].values["GDIGateOne"]; - #ifdef RA2_MODE // RULES(MD).INI has the incorrect colors set for the following houses, let's remap them to the expected values. // Fixup YuriCountry colour - if (rules.sections["YuriCountry"].GetValueByName("Color") == "DarkRed") { - rules.sections["YuriCountry"].values["Color"] = "Purple"; + if (rules.GetString("YuriCountry", "Color") == "DarkRed") { + rules.SetString("YuriCountry", "Color", "Purple"); } // Fixup Allied colors - std::list allied_houses; - allied_houses.push_back("British"); - allied_houses.push_back("French"); - allied_houses.push_back("Germans"); - allied_houses.push_back("Americans"); - allied_houses.push_back("Alliance"); - for (std::list::iterator it = allied_houses.begin(); it != allied_houses.end(); ++it) { - if (rules.sections[*it].GetValueByName("Color") == "Gold") { - rules.sections[*it].values["Color"] = "DarkBlue"; + static const char* allied_houses[] = { + "British", + "French", + "Germans", + "Americans", + "Alliance", + }; + + for (auto const& name : allied_houses) { + if (rules.GetString(name, "Color") == "Gold") { + rules.SetString(name, "Color", "DarkBlue"); } } // Fixup Nod color - if (rules.sections["Nod"].GetValueByName("Color") == "Gold") { - rules.sections["Nod"].values["Color"] = "DarkRed"; + if (rules.GetString("Nod", "Color") == "Gold") { + rules.SetString("Nod", "Color", "DarkRed"); } #endif @@ -6530,12 +5152,14 @@ void CLoading::PrepareUnitGraphic(LPCSTR lpUnittype) WORD wStep=1; // step is 1 for infantry, buildings, etc, and for shp vehicles it specifies the step rate between every direction WORD wStartWalkFrame=0; // for examply cyborg reaper has another walk starting frame int iTurretOffset=0; // used for centering y pos of turret (if existing) - BOOL bStructure=rules.sections["BuildingTypes"].FindValue(lpUnittype)>=0; // is this a structure? + BOOL bStructure = rules["BuildingTypes"].HasValue(lpUnittype); // is this a structure? - if(!bStructure) return; // make sure we only use it for buildings now + // make sure we only use it for buildings now + if (!bStructure) { + return; + } + auto const bPowerUp = !rules.GetString(lpUnittype, "PowersUpBuilding").IsEmpty(); - BOOL bPowerUp=rules.sections[lpUnittype].values["PowersUpBuilding"]!=""; - HTSPALETTE hPalette; if(theat=='T') hPalette=m_hPalIsoTemp; if(theat=='A') hPalette=m_hPalIsoSnow; @@ -6547,22 +5171,23 @@ void CLoading::PrepareUnitGraphic(LPCSTR lpUnittype) CIsoView& v=*((CFinalSunDlg*)theApp.m_pMainWnd)->m_view.m_isoview; _rules_image=lpUnittype; - if(rules.sections[lpUnittype].values.find("Image")!=rules.sections[lpUnittype].values.end()) - _rules_image=rules.sections[lpUnittype].values["Image"]; + auto const& imageID = rules.GetString(lpUnittype, "Image"); + if (!imageID.IsEmpty()) { + _rules_image= imageID; + } CString _art_image = _rules_image; - if(art.sections[_rules_image].values.find("Image")!=art.sections[_rules_image].values.end()) - { - if(!isTrue(g_data.sections["IgnoreArtImage"].values[_rules_image])) - _art_image=art.sections[_rules_image].values["Image"]; + auto const& imageID = art.GetString(_rules_image, "Image"); + if (!imageID.IsEmpty() && !g_data.GetBool("IgnoreArtImage", _rules_image)) { + _art_image = imageID; } const CString& image = _art_image; - const auto& rulesSection = rules.sections[lpUnittype]; - const auto& artSection = art.sections[image]; + const auto& rulesSection = rules[lpUnittype]; + const auto& artSection = art[image]; - if(!isTrue(art.sections[image].values["Voxel"])) // is it a shp graphic? - { + // is it a shp graphic? + if(!artSection.GetBool("Voxel")) { try { @@ -6782,28 +5407,23 @@ void CLoading::PrepareUnitGraphic(LPCSTR lpUnittype) }*/ auto shp = FindUnitShp(image, cur_theat, artSection); - if (!shp) + if (!shp) { return; + } filename = shp->filename; hPalette = shp->palette; - auto limited_to_theater = isTrue(artSection.GetValueByName("TerrainPalette")) ? shp->mixfile_theater : TheaterChar::None; + auto limited_to_theater = artSection.GetBool("TerrainPalette") ? shp->mixfile_theater : TheaterChar::None; - if(filename=="tibtre01.tem" || filename=="tibtre02.tem" || filename=="tibtre03.tem" || filename=="veinhole.tem") - { + if(filename=="tibtre01.tem" || filename=="tibtre02.tem" || filename=="tibtre03.tem" || filename=="veinhole.tem") { hPalette=m_hPalUnitTemp; } - - - if(shp->mixfile>0) - { - BOOL bSuccess=FSunPackLib::SetCurrentSHP(filename, shp->mixfile); - if( - !bSuccess - ) - { + if (shp->mixfile > 0) { + + BOOL bSuccess = FSunPackLib::SetCurrentSHP(filename, shp->mixfile); + if (!bSuccess) { filename=image+".sno"; if(cur_theat=='T' || cur_theat=='U') hPalette=m_hPalIsoTemp; HMIXFILE hShpMix=FindFileInMix(filename); @@ -6941,14 +5561,11 @@ void CLoading::FetchPalettes() FSunPackLib::ColorConverter conf(pf); - const auto& rulesColors = rules.sections["Colors"]; - for(i=0;i< rulesColors.values.size();i++) - { - CString col=*rulesColors.GetValueName(i); - COLORREF cref=v.GetColor("", col); + for (auto const& [name, col] : rules["Colors"]) { + COLORREF cref = v.GetColor("", col); - color_conv[col]=conf.GetColor(GetRValue(cref), GetGValue(cref), GetBValue(cref)); - colorref_conv[cref]=color_conv[col]; + color_conv[col] = conf.GetColor(GetRValue(cref), GetGValue(cref), GetBValue(cref)); + colorref_conv[cref] = color_conv[col]; } } diff --git a/MissionEditor/Loading.h b/MissionEditor/Loading.h index eb07890..70eb665 100644 --- a/MissionEditor/Loading.h +++ b/MissionEditor/Loading.h @@ -110,9 +110,9 @@ public: CLoading(CWnd* pParent = NULL); // Standardconstructor void InitPics(CProgressCtrl* prog=NULL); void Load(); - BOOL LoadUnitGraphic(LPCTSTR lpUnittype); + BOOL LoadUnitGraphic(const CString& lpUnittype); void LoadBuildingSubGraphic(const CString& subkey, const CIniFileSection& artSection, BOOL bAlwaysSetChar, char theat, HMIXFILE hShpMix, SHPHEADER& shp_h, BYTE*& shp); - void LoadOverlayGraphic(LPCTSTR lpOvrlName, int iOvrlNum); + void LoadOverlayGraphic(const CString& lpOvrlName, int iOvrlNum); void InitVoxelNormalTables(); HTSPALETTE GetIsoPalette(char theat); HTSPALETTE GetUnitPalette(char theat); diff --git a/MissionEditor/Loading_old.cpp b/MissionEditor/Loading_old.cpp new file mode 100644 index 0000000..fe0e11d Binary files /dev/null and b/MissionEditor/Loading_old.cpp differ