diff --git a/.github/workflows/verify.yml b/.github/workflows/verify.yml new file mode 100644 index 0000000..32d5b6b --- /dev/null +++ b/.github/workflows/verify.yml @@ -0,0 +1,36 @@ +name: Basic verify + +on: + push: + branches: [ "!main", "!RN", "*" ] + +jobs: + compile-check: + runs-on: windows-2019 + env: + CONFIGURATION: Debug + + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 1 + submodules: recursive + - name: Change configuration to debug for PR + if: github.event_name == 'pull_request' + shell: bash + run: | + echo "CONFIGURATION=FinalAlertDebug YR" >> $GITHUB_ENV + mkdir Debug || true + + - name: setup-msvc + uses: egor-tensin/vs-shell@v2 + with: + # Target architecture + arch: x64 + - name: build-msvc + run: | + devenv.com "MissionEditor.sln" /Build "${{ env.CONFIGURATION }}|x64" /project UnitTest + - name: do UT + run: | + cd x64\Debug + ./UnitTest \ No newline at end of file diff --git a/.gitignore b/.gitignore index d07bc44..224012b 100644 --- a/.gitignore +++ b/.gitignore @@ -42,9 +42,6 @@ build_*/ *.ncb *.sdf *.suo -*.sln -*.vcxproj -*.filters *.aps # CMake diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..d49ab5c --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "gtest-lib"] + path = googletest + url = ../gtest-lib.git diff --git a/3rdParty/xcc/Library/StdAfx.h b/3rdParty/xcc/Library/StdAfx.h index ce37391..45cdcb9 100644 --- a/3rdParty/xcc/Library/StdAfx.h +++ b/3rdParty/xcc/Library/StdAfx.h @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include diff --git a/3rdParty/xcc/Library/XCC Library.vcxproj b/3rdParty/xcc/Library/XCC Library.vcxproj index 857d3f8..2b8ff7c 100644 --- a/3rdParty/xcc/Library/XCC Library.vcxproj +++ b/3rdParty/xcc/Library/XCC Library.vcxproj @@ -5,18 +5,34 @@ DebugMinimal Win32 + + DebugMinimal + x64 + Debug Win32 + + Debug + x64 + ReleaseMinimal Win32 + + ReleaseMinimal + x64 + Release Win32 + + Release + x64 + {5E445578-CB45-4D82-9A1C-FC7D3E8D866A} @@ -34,6 +50,15 @@ true v143 + + $(SolutionDir)\build\output\$(Configuration)-$(Platform)\lib\ + $(SolutionDir)\build\intermediate\$(Configuration)-$(Platform)\$(ProjectName)\ + StaticLibrary + Dynamic + MultiByte + true + v143 + $(SolutionDir)\build\output\$(Configuration)-$(Platform)\lib\ $(SolutionDir)\build\intermediate\$(Configuration)-$(Platform)\$(ProjectName)\ @@ -43,6 +68,15 @@ true v143 + + $(SolutionDir)\build\output\$(Configuration)-$(Platform)\lib\ + $(SolutionDir)\build\intermediate\$(Configuration)-$(Platform)\$(ProjectName)\ + StaticLibrary + Dynamic + MultiByte + true + v143 + $(SolutionDir)\build\output\$(Configuration)-$(Platform)\lib\ $(SolutionDir)\build\intermediate\$(Configuration)-$(Platform)\$(ProjectName)\ @@ -51,6 +85,14 @@ MultiByte v143 + + $(SolutionDir)\build\output\$(Configuration)-$(Platform)\lib\ + $(SolutionDir)\build\intermediate\$(Configuration)-$(Platform)\$(ProjectName)\ + StaticLibrary + Dynamic + MultiByte + v143 + $(SolutionDir)\build\output\$(Configuration)-$(Platform)\lib\ $(SolutionDir)\build\intermediate\$(Configuration)-$(Platform)\$(ProjectName)\ @@ -59,6 +101,14 @@ MultiByte v143 + + $(SolutionDir)\build\output\$(Configuration)-$(Platform)\lib\ + $(SolutionDir)\build\intermediate\$(Configuration)-$(Platform)\$(ProjectName)\ + StaticLibrary + Dynamic + MultiByte + v143 + @@ -86,18 +136,34 @@ + + + + + + + + + + + + + + + + <_ProjectFileVersion>10.0.30319.1 @@ -120,6 +186,21 @@ 0x0413 + + + Disabled + _DEBUG;WIN32;_LIB;$(XCC_MINIMAL_BUILD);$(NO_FT_SUPPORT);%(PreprocessorDefinitions) + EnableFastChecks + MultiThreadedDebugDLL + Use + stdafx.h + stdcpp20 + + + _DEBUG;%(PreprocessorDefinitions) + 0x0413 + + Disabled @@ -135,6 +216,21 @@ 0x0413 + + + Disabled + _DEBUG;WIN32;_LIB;$(XCC_MINIMAL_BUILD);$(NO_FT_SUPPORT);%(PreprocessorDefinitions) + EnableFastChecks + MultiThreadedDebugDLL + Use + stdafx.h + stdcpplatest + + + _DEBUG;%(PreprocessorDefinitions) + 0x0413 + + NDEBUG;WIN32;_LIB;$(XCC_MINIMAL_BUILD);$(NO_FT_SUPPORT);%(PreprocessorDefinitions) @@ -150,6 +246,21 @@ 0x0413 + + + NDEBUG;WIN32;_LIB;$(XCC_MINIMAL_BUILD);$(NO_FT_SUPPORT);%(PreprocessorDefinitions) + true + MultiThreaded + true + Use + stdafx.h + stdcpplatest + + + NDEBUG;%(PreprocessorDefinitions) + 0x0413 + + NDEBUG;WIN32;_LIB;$(XCC_MINIMAL_BUILD);$(NO_FT_SUPPORT);%(PreprocessorDefinitions) @@ -165,6 +276,21 @@ 0x0413 + + + NDEBUG;WIN32;_LIB;$(XCC_MINIMAL_BUILD);$(NO_FT_SUPPORT);%(PreprocessorDefinitions) + true + MultiThreadedDLL + true + Use + stdafx.h + stdcpplatest + + + NDEBUG;%(PreprocessorDefinitions) + 0x0413 + + true @@ -350,9 +476,13 @@ Create + Create Create + Create Create + Create Create + Create diff --git a/3rdParty/xcc/misc/blowfish.cpp b/3rdParty/xcc/misc/blowfish.cpp index 9e1833c..37f75e5 100644 --- a/3rdParty/xcc/misc/blowfish.cpp +++ b/3rdParty/xcc/misc/blowfish.cpp @@ -385,15 +385,9 @@ void Cblowfish::decipher(uint32_t& xl, uint32_t& xr) const static uint32_t reverse(uint32_t v) { - _asm - { - mov eax, v - xchg al, ah - rol eax, 16 - xchg al, ah - mov v, eax - } - return v; + uint32_t result = ((v & 0x00FF00FF) << 8) | ((v & 0xFF00FF00) >> 8); + result = (result << 16) | (result >> 16); + return result; } void Cblowfish::encipher(const void* s, void* d, int size) const diff --git a/3rdParty/xcc/misc/blowfish.h b/3rdParty/xcc/misc/blowfish.h index 72a3f3f..62aab66 100644 --- a/3rdParty/xcc/misc/blowfish.h +++ b/3rdParty/xcc/misc/blowfish.h @@ -19,6 +19,7 @@ #pragma once #include +#include class Cblowfish { diff --git a/3rdParty/xcc/misc/cc_structures.h b/3rdParty/xcc/misc/cc_structures.h index 2e93ff5..ff3ac5d 100644 --- a/3rdParty/xcc/misc/cc_structures.h +++ b/3rdParty/xcc/misc/cc_structures.h @@ -43,17 +43,12 @@ enum t_game const char* game_name[]; -inline __int32 reverse(__int32 v) + +static int32_t reverse(int32_t v) { - _asm - { - mov eax, v - xchg al, ah - rol eax, 16 - xchg al, ah - mov v, eax - } - return v; + uint32_t result = ((v & 0x00FF00FF) << 8) | ((v & 0xFF00FF00) >> 8); + result = (result << 16) | (result >> 16); + return result; } #pragma pack(push, 1) diff --git a/3rdParty/xcc/misc/mix_file.h b/3rdParty/xcc/misc/mix_file.h index fbf6681..cb11e7b 100644 --- a/3rdParty/xcc/misc/mix_file.h +++ b/3rdParty/xcc/misc/mix_file.h @@ -48,7 +48,7 @@ public: m_mix_expansion = true; } - int get_c_files() const + auto get_c_files() const { return m_index.size(); } diff --git a/3rdParty/xcc/misc/shp_decode.cpp b/3rdParty/xcc/misc/shp_decode.cpp index e78be75..fd1402d 100644 --- a/3rdParty/xcc/misc/shp_decode.cpp +++ b/3rdParty/xcc/misc/shp_decode.cpp @@ -377,45 +377,47 @@ static void write_v80(byte v, int count, byte*& d) } } +#include + void get_same(const byte* s, const byte* r, const byte* s_end, byte*& p, int& cb_p) { - _asm - { - push esi - push edi - mov eax, s_end - mov ebx, s - xor ecx, ecx - mov edi, p - mov [edi], ecx - dec ebx + const byte* s_end_ptr = s_end; + const byte* s_ptr = s; + int ecx_value = 0; + byte* edi_ptr = p; + *edi_ptr = static_cast(ecx_value); + s_ptr--; + next_s: - inc ebx - xor edx, edx - mov esi, r - mov edi, ebx - cmp edi, esi - jnb end0 + s_ptr++; + int edx_value = 0; + const byte* esi_ptr = r; + const byte* edi_val = s_ptr; + if (edi_val >= esi_ptr) + goto end0; + next0: - inc edx - cmp esi, eax - jnb end_line - cmpsb - je next0 + edx_value++; + if (esi_ptr >= s_end_ptr) + goto end_line; + + if (*esi_ptr == *s_ptr) + goto next0; + end_line: - dec edx - cmp edx, ecx - jl next_s - mov ecx, edx - mov edi, p - mov [edi], ebx - jmp next_s + edx_value--; + if (edx_value < ecx_value) + goto next_s; + + ecx_value = edx_value; + edi_ptr = p; + *edi_ptr = static_cast(*s_ptr); + goto next_s; + end0: - mov edi, cb_p - mov [edi], ecx - pop edi - pop esi - } + edi_ptr = reinterpret_cast(& cb_p); + *edi_ptr = ecx_value; + // Restore registers } static void write80_c0(byte*& w, int count, int p) @@ -617,162 +619,144 @@ int decode80c(const byte image_in[], byte image_out[], int cb_in) return (w - image_out); } -int decode80(const byte image_in[], byte image_out[]) +int __fastcall decode80(const byte image_in[], byte image_out[]) { - int cb_out; - /* - 0 copy 0cccpppp p - 1 copy 10cccccc - 2 copy 11cccccc p p - 3 fill 11111110 c c v - 4 copy 11111111 c c p p - */ - - _asm + byte* i; // edi + unsigned int v4; // eax + const byte* v5; // esi + unsigned int v6; // ecx + int v7; // eax + const byte* v8; // edx + byte* v9; // esi + unsigned int v10; // ecx + unsigned int v11; // eax + const byte* v12; // esi + unsigned int v13; // ecx + char v14; // al + + for (i = image_out; ; i += v10) { - push esi - push edi - mov ax, ds - mov es, ax - mov esi, image_in - mov edi, image_out -next0: - xor eax, eax - lodsb - mov ecx, eax - test eax, 0x80 - jnz c1c - shr ecx, 4 - add ecx, 3 - and eax, 0xf - shl eax, 8 - lodsb - mov edx, esi - mov esi, edi - sub esi, eax - jmp copy_from_destination -c1c: - and ecx, 0x3f - test eax, 0x40 - jnz c2c - or ecx, ecx - jz end0 - jmp copy_from_source -c2c: - xor eax, eax - lodsw - cmp ecx, 0x3e - je c3 - ja c4 - mov edx, esi - mov esi, image_out - add esi, eax - add ecx, 3 - jmp copy_from_destination -c3: - mov ecx, eax - lodsb - rep stosb - jmp next0 -c4: - mov ecx, eax - lodsw - mov edx, esi - mov esi, image_out - add esi, eax -copy_from_destination: - rep movsb - mov esi, edx - jmp next0 -copy_from_source: - rep movsb - jmp next0 -end0: - sub edi, image_out - mov cb_out, edi - pop edi - pop esi + while (1) + { + v4 = (unsigned __int8)*image_in; + v5 = image_in + 1; + if ((v4 & 0x80) == 0) + { + v6 = (v4 >> 4) + 3; + v7 = (v4 & 0xF) << 8; + v7 |= static_cast(*v5); + v8 = v5 + 1; + v9 = &i[-v7]; + goto copy_from_destination; + } + v10 = v4 & 0x3F; + if ((v4 & 0x40) == 0) + break; + v11 = *(unsigned __int16*)v5; + v12 = v5 + 2; + if (v10 == 62) + { + v13 = v11; + v14 = *v12; + image_in = v12 + 1; + memset(i, v14, v13); + i += v13; + } else + { + if (v10 > 0x3E) + { + v6 = v11; + v11 = *reinterpret_cast(v12); + v8 = v12 + 2; + v9 = &image_out[v11]; + } else + { + v8 = v12; + v9 = &image_out[v11]; + v6 = v10 + 3; + } + copy_from_destination: + memcpy(i, v9, v6); + i += v6; + image_in = v8; + } + } + if ((v4 & 0x3F) == 0) + break; + memcpy(i, v5, v10); + image_in = &v5[v10]; } - return cb_out; + return i - image_out; } -int decode80r(const byte image_in[], byte image_out[]) +int __fastcall decode80r(const byte image_in[], byte image_out[]) { - int cb_out; - /* - 0 copy 0cccpppp p - 1 copy 10cccccc - 2 copy 11cccccc p p - 3 fill 11111110 c c v - 4 copy 11111111 c c p p - */ - - _asm + byte* i; // edi + unsigned int v4; // eax + const byte* v5; // esi + unsigned int v6; // ecx + int v7; // eax + const byte* v8; // edx + byte* v9; // esi + unsigned int v10; // ecx + unsigned int v11; // eax + const byte* v12; // esi + unsigned int v13; // ecx + char v14; // al + + for (i = image_out; ; i += v10) { - push esi - push edi - mov ax, ds - mov es, ax - mov esi, image_in - mov edi, image_out -next0: - xor eax, eax - lodsb - mov ecx, eax - test eax, 0x80 - jnz c1c - shr ecx, 4 - add ecx, 3 - and eax, 0xf - shl eax, 8 - lodsb - mov edx, esi - mov esi, edi - sub esi, eax - jmp copy_from_destination -c1c: - and ecx, 0x3f - test eax, 0x40 - jnz c2c - or ecx, ecx - jz end0 - jmp copy_from_source -c2c: - xor eax, eax - lodsw - cmp ecx, 0x3e - je c3 - ja c4 - mov edx, esi - mov esi, edi - sub esi, eax - add ecx, 3 - jmp copy_from_destination -c3: - mov ecx, eax - lodsb - rep stosb - jmp next0 -c4: - mov ecx, eax - lodsw - mov edx, esi - mov esi, edi - sub esi, eax -copy_from_destination: - rep movsb - mov esi, edx - jmp next0 -copy_from_source: - rep movsb - jmp next0 -end0: - sub edi, image_out - mov cb_out, edi - pop edi - pop esi + while (1) + { + v4 = (unsigned __int8)*image_in; + v5 = image_in + 1; + if ((v4 & 0x80) == 0) + { + v6 = (v4 >> 4) + 3; + v7 = (v4 & 0xF) << 8; + v7 |= static_cast(*v5); + v8 = v5 + 1; + v9 = &i[-v7]; + goto copy_from_destination; + } + v10 = v4 & 0x3F; + if ((v4 & 0x40) == 0) + break; + v11 = *(unsigned __int16*)v5; + v12 = v5 + 2; + if (v10 == 62) + { + v13 = v11; + v14 = *v12; + image_in = v12 + 1; + memset(i, v14, v13); + i += v13; + } else + { + if (v10 > 0x3E) + { + v6 = v11; + v11 = *reinterpret_cast(v12); + v8 = v12 + 2; + v9 = &i[-v11]; + } else + { + v8 = v12; + v9 = &i[-v11]; + v6 = v10 + 3; + } + copy_from_destination: + memcpy(i, v9, v6); + i += v6; + image_in = v8; + } + } + if ((v4 & 0x3F) == 0) + break; + memcpy(i, v5, v10); + image_in = &v5[v10]; } - return cb_out; + return i - image_out; } int decode2(const byte* s, byte* d, int cb_s, const byte* reference_palet) @@ -1167,7 +1151,7 @@ int encode5(const byte* s, byte* d, int cb_s, int format) byte* w = d; while (r < r_end) { - int cb_section = min(r_end - r, 8192); + int cb_section = min(r_end - r, 8192); t_pack_section_header& header = *reinterpret_cast(w); w += sizeof(t_pack_section_header); w += header.size_in = format == 80 ? encode80(r, w, cb_section) : encode5s(r, w, cb_section); diff --git a/3rdParty/xcc/misc/tmp_ts_file.h b/3rdParty/xcc/misc/tmp_ts_file.h index 43958bf..8d6e702 100644 --- a/3rdParty/xcc/misc/tmp_ts_file.h +++ b/3rdParty/xcc/misc/tmp_ts_file.h @@ -34,7 +34,7 @@ public: bool is_valid() const { const t_tmp_ts_header& h = header(); - int size = get_size(); + auto const size = get_size(); if (sizeof(t_tmp_ts_header) > size || !h.cblocks_x || !h.cblocks_y || h.cx != 48 && h.cx != 60 || @@ -183,8 +183,8 @@ public: const byte* get_z_image(int i) const { - int a = get_index()[i] + get_image_header(i)->z_ofs; - int b = get_image(i) + get_cb_diamond() - data(); + auto const a = get_index()[i] + get_image_header(i)->z_ofs; + auto const b = get_image(i) + get_cb_diamond() - data(); assert(a == b); return data() + get_index()[i] + get_image_header(i)->z_ofs; } diff --git a/3rdParty/xcc/misc/vartypes.h b/3rdParty/xcc/misc/vartypes.h index 9621128..8f6482c 100644 --- a/3rdParty/xcc/misc/vartypes.h +++ b/3rdParty/xcc/misc/vartypes.h @@ -1,3 +1,4 @@ +#pragma once /* XCC Utilities and Library Copyright (C) 2000 Olaf van der Spek diff --git a/3rdParty/xcc/misc/virtual_tfile.h b/3rdParty/xcc/misc/virtual_tfile.h index 418be44..812b5aa 100644 --- a/3rdParty/xcc/misc/virtual_tfile.h +++ b/3rdParty/xcc/misc/virtual_tfile.h @@ -32,7 +32,7 @@ private: return reinterpret_cast(m_data.data()); } - int size() const + auto size() const { return m_data.size(); } diff --git a/3rdParty/xcc/misc/vxl_file.h b/3rdParty/xcc/misc/vxl_file.h index 5dd1857..576bcd3 100644 --- a/3rdParty/xcc/misc/vxl_file.h +++ b/3rdParty/xcc/misc/vxl_file.h @@ -45,7 +45,7 @@ public: int get_c_spans(int i) const { - return get_section_tailer(i)->span_end_ofs - get_section_tailer(i)->span_start_ofs >> 2; + return (get_section_tailer(i)->span_end_ofs - get_section_tailer(i)->span_start_ofs) >> 2; } int get_c_section_tailers() const diff --git a/MissionEditor.sln b/MissionEditor.sln index 53dd158..9993885 100644 --- a/MissionEditor.sln +++ b/MissionEditor.sln @@ -15,66 +15,192 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MissionEditorPackLib", "Mis EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "XCC Library", "3rdParty\xcc\Library\XCC Library.vcxproj", "{5E445578-CB45-4D82-9A1C-FC7D3E8D866A}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UnitTest", "UnitTest\UnitTest.vcxproj", "{75E18879-7564-4A2C-8C00-393A5A17171F}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 FinalAlertDebug YR|Win32 = FinalAlertDebug YR|Win32 + FinalAlertDebug YR|x64 = FinalAlertDebug YR|x64 FinalAlertDebug|Win32 = FinalAlertDebug|Win32 + FinalAlertDebug|x64 = FinalAlertDebug|x64 FinalAlertRelease YR|Win32 = FinalAlertRelease YR|Win32 + FinalAlertRelease YR|x64 = FinalAlertRelease YR|x64 FinalAlertRelease|Win32 = FinalAlertRelease|Win32 + FinalAlertRelease|x64 = FinalAlertRelease|x64 FinalSunDebug|Win32 = FinalSunDebug|Win32 + FinalSunDebug|x64 = FinalSunDebug|x64 FinalSunRelease|Win32 = FinalSunRelease|Win32 + FinalSunRelease|x64 = FinalSunRelease|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 Template|Win32 = Template|Win32 + Template|x64 = Template|x64 Tests FinalAlertDebug YR|Win32 = Tests FinalAlertDebug YR|Win32 + Tests FinalAlertDebug YR|x64 = Tests FinalAlertDebug YR|x64 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution + {9326D29A-6547-42B9-A668-519F3C0720A9}.Debug|Win32.ActiveCfg = Tests FinalAlertDebug YR|Win32 + {9326D29A-6547-42B9-A668-519F3C0720A9}.Debug|Win32.Build.0 = Tests FinalAlertDebug YR|Win32 + {9326D29A-6547-42B9-A668-519F3C0720A9}.Debug|x64.ActiveCfg = Tests FinalAlertDebug YR|x64 + {9326D29A-6547-42B9-A668-519F3C0720A9}.Debug|x64.Build.0 = Tests FinalAlertDebug YR|x64 {9326D29A-6547-42B9-A668-519F3C0720A9}.FinalAlertDebug YR|Win32.ActiveCfg = FinalAlertDebug YR|Win32 {9326D29A-6547-42B9-A668-519F3C0720A9}.FinalAlertDebug YR|Win32.Build.0 = FinalAlertDebug YR|Win32 + {9326D29A-6547-42B9-A668-519F3C0720A9}.FinalAlertDebug YR|x64.ActiveCfg = FinalAlertDebug YR|x64 + {9326D29A-6547-42B9-A668-519F3C0720A9}.FinalAlertDebug YR|x64.Build.0 = FinalAlertDebug YR|x64 {9326D29A-6547-42B9-A668-519F3C0720A9}.FinalAlertDebug|Win32.ActiveCfg = FinalAlertDebug|Win32 {9326D29A-6547-42B9-A668-519F3C0720A9}.FinalAlertDebug|Win32.Build.0 = FinalAlertDebug|Win32 + {9326D29A-6547-42B9-A668-519F3C0720A9}.FinalAlertDebug|x64.ActiveCfg = FinalAlertDebug|x64 + {9326D29A-6547-42B9-A668-519F3C0720A9}.FinalAlertDebug|x64.Build.0 = FinalAlertDebug|x64 {9326D29A-6547-42B9-A668-519F3C0720A9}.FinalAlertRelease YR|Win32.ActiveCfg = FinalAlertRelease YR|Win32 {9326D29A-6547-42B9-A668-519F3C0720A9}.FinalAlertRelease YR|Win32.Build.0 = FinalAlertRelease YR|Win32 + {9326D29A-6547-42B9-A668-519F3C0720A9}.FinalAlertRelease YR|x64.ActiveCfg = FinalAlertRelease YR|x64 + {9326D29A-6547-42B9-A668-519F3C0720A9}.FinalAlertRelease YR|x64.Build.0 = FinalAlertRelease YR|x64 {9326D29A-6547-42B9-A668-519F3C0720A9}.FinalAlertRelease|Win32.ActiveCfg = FinalAlertRelease|Win32 {9326D29A-6547-42B9-A668-519F3C0720A9}.FinalAlertRelease|Win32.Build.0 = FinalAlertRelease|Win32 + {9326D29A-6547-42B9-A668-519F3C0720A9}.FinalAlertRelease|x64.ActiveCfg = FinalAlertRelease|x64 + {9326D29A-6547-42B9-A668-519F3C0720A9}.FinalAlertRelease|x64.Build.0 = FinalAlertRelease|x64 {9326D29A-6547-42B9-A668-519F3C0720A9}.FinalSunDebug|Win32.ActiveCfg = FinalSunDebug|Win32 {9326D29A-6547-42B9-A668-519F3C0720A9}.FinalSunDebug|Win32.Build.0 = FinalSunDebug|Win32 + {9326D29A-6547-42B9-A668-519F3C0720A9}.FinalSunDebug|x64.ActiveCfg = FinalSunDebug|x64 + {9326D29A-6547-42B9-A668-519F3C0720A9}.FinalSunDebug|x64.Build.0 = FinalSunDebug|x64 {9326D29A-6547-42B9-A668-519F3C0720A9}.FinalSunRelease|Win32.ActiveCfg = FinalSunRelease|Win32 {9326D29A-6547-42B9-A668-519F3C0720A9}.FinalSunRelease|Win32.Build.0 = FinalSunRelease|Win32 + {9326D29A-6547-42B9-A668-519F3C0720A9}.FinalSunRelease|x64.ActiveCfg = FinalSunRelease|x64 + {9326D29A-6547-42B9-A668-519F3C0720A9}.FinalSunRelease|x64.Build.0 = FinalSunRelease|x64 + {9326D29A-6547-42B9-A668-519F3C0720A9}.Release|Win32.ActiveCfg = FinalSunRelease|Win32 + {9326D29A-6547-42B9-A668-519F3C0720A9}.Release|Win32.Build.0 = FinalSunRelease|Win32 + {9326D29A-6547-42B9-A668-519F3C0720A9}.Release|x64.ActiveCfg = FinalSunRelease|x64 + {9326D29A-6547-42B9-A668-519F3C0720A9}.Release|x64.Build.0 = FinalSunRelease|x64 {9326D29A-6547-42B9-A668-519F3C0720A9}.Template|Win32.ActiveCfg = Template|Win32 {9326D29A-6547-42B9-A668-519F3C0720A9}.Template|Win32.Build.0 = Template|Win32 + {9326D29A-6547-42B9-A668-519F3C0720A9}.Template|x64.ActiveCfg = Template|x64 + {9326D29A-6547-42B9-A668-519F3C0720A9}.Template|x64.Build.0 = Template|x64 {9326D29A-6547-42B9-A668-519F3C0720A9}.Tests FinalAlertDebug YR|Win32.ActiveCfg = Tests FinalAlertDebug YR|Win32 {9326D29A-6547-42B9-A668-519F3C0720A9}.Tests FinalAlertDebug YR|Win32.Build.0 = Tests FinalAlertDebug YR|Win32 + {9326D29A-6547-42B9-A668-519F3C0720A9}.Tests FinalAlertDebug YR|x64.ActiveCfg = Tests FinalAlertDebug YR|x64 + {9326D29A-6547-42B9-A668-519F3C0720A9}.Tests FinalAlertDebug YR|x64.Build.0 = Tests FinalAlertDebug YR|x64 + {DEB40EF0-E215-4C2F-A0AD-3742E2E01A8C}.Debug|Win32.ActiveCfg = Debug|Win32 + {DEB40EF0-E215-4C2F-A0AD-3742E2E01A8C}.Debug|Win32.Build.0 = Debug|Win32 + {DEB40EF0-E215-4C2F-A0AD-3742E2E01A8C}.Debug|x64.ActiveCfg = Debug|x64 + {DEB40EF0-E215-4C2F-A0AD-3742E2E01A8C}.Debug|x64.Build.0 = Debug|x64 {DEB40EF0-E215-4C2F-A0AD-3742E2E01A8C}.FinalAlertDebug YR|Win32.ActiveCfg = Debug|Win32 {DEB40EF0-E215-4C2F-A0AD-3742E2E01A8C}.FinalAlertDebug YR|Win32.Build.0 = Debug|Win32 + {DEB40EF0-E215-4C2F-A0AD-3742E2E01A8C}.FinalAlertDebug YR|x64.ActiveCfg = Debug|x64 + {DEB40EF0-E215-4C2F-A0AD-3742E2E01A8C}.FinalAlertDebug YR|x64.Build.0 = Debug|x64 {DEB40EF0-E215-4C2F-A0AD-3742E2E01A8C}.FinalAlertDebug|Win32.ActiveCfg = Debug|Win32 {DEB40EF0-E215-4C2F-A0AD-3742E2E01A8C}.FinalAlertDebug|Win32.Build.0 = Debug|Win32 + {DEB40EF0-E215-4C2F-A0AD-3742E2E01A8C}.FinalAlertDebug|x64.ActiveCfg = Debug|x64 + {DEB40EF0-E215-4C2F-A0AD-3742E2E01A8C}.FinalAlertDebug|x64.Build.0 = Debug|x64 {DEB40EF0-E215-4C2F-A0AD-3742E2E01A8C}.FinalAlertRelease YR|Win32.ActiveCfg = Release|Win32 {DEB40EF0-E215-4C2F-A0AD-3742E2E01A8C}.FinalAlertRelease YR|Win32.Build.0 = Release|Win32 + {DEB40EF0-E215-4C2F-A0AD-3742E2E01A8C}.FinalAlertRelease YR|x64.ActiveCfg = Release|x64 + {DEB40EF0-E215-4C2F-A0AD-3742E2E01A8C}.FinalAlertRelease YR|x64.Build.0 = Release|x64 {DEB40EF0-E215-4C2F-A0AD-3742E2E01A8C}.FinalAlertRelease|Win32.ActiveCfg = Release|Win32 {DEB40EF0-E215-4C2F-A0AD-3742E2E01A8C}.FinalAlertRelease|Win32.Build.0 = Release|Win32 + {DEB40EF0-E215-4C2F-A0AD-3742E2E01A8C}.FinalAlertRelease|x64.ActiveCfg = Release|x64 + {DEB40EF0-E215-4C2F-A0AD-3742E2E01A8C}.FinalAlertRelease|x64.Build.0 = Release|x64 {DEB40EF0-E215-4C2F-A0AD-3742E2E01A8C}.FinalSunDebug|Win32.ActiveCfg = Debug|Win32 {DEB40EF0-E215-4C2F-A0AD-3742E2E01A8C}.FinalSunDebug|Win32.Build.0 = Debug|Win32 + {DEB40EF0-E215-4C2F-A0AD-3742E2E01A8C}.FinalSunDebug|x64.ActiveCfg = Debug|x64 + {DEB40EF0-E215-4C2F-A0AD-3742E2E01A8C}.FinalSunDebug|x64.Build.0 = Debug|x64 {DEB40EF0-E215-4C2F-A0AD-3742E2E01A8C}.FinalSunRelease|Win32.ActiveCfg = Release|Win32 {DEB40EF0-E215-4C2F-A0AD-3742E2E01A8C}.FinalSunRelease|Win32.Build.0 = Release|Win32 + {DEB40EF0-E215-4C2F-A0AD-3742E2E01A8C}.FinalSunRelease|x64.ActiveCfg = Release|x64 + {DEB40EF0-E215-4C2F-A0AD-3742E2E01A8C}.FinalSunRelease|x64.Build.0 = Release|x64 + {DEB40EF0-E215-4C2F-A0AD-3742E2E01A8C}.Release|Win32.ActiveCfg = Release|Win32 + {DEB40EF0-E215-4C2F-A0AD-3742E2E01A8C}.Release|Win32.Build.0 = Release|Win32 + {DEB40EF0-E215-4C2F-A0AD-3742E2E01A8C}.Release|x64.ActiveCfg = Release|x64 + {DEB40EF0-E215-4C2F-A0AD-3742E2E01A8C}.Release|x64.Build.0 = Release|x64 {DEB40EF0-E215-4C2F-A0AD-3742E2E01A8C}.Template|Win32.ActiveCfg = Debug|Win32 {DEB40EF0-E215-4C2F-A0AD-3742E2E01A8C}.Template|Win32.Build.0 = Debug|Win32 + {DEB40EF0-E215-4C2F-A0AD-3742E2E01A8C}.Template|x64.ActiveCfg = Debug|x64 + {DEB40EF0-E215-4C2F-A0AD-3742E2E01A8C}.Template|x64.Build.0 = Debug|x64 {DEB40EF0-E215-4C2F-A0AD-3742E2E01A8C}.Tests FinalAlertDebug YR|Win32.ActiveCfg = Debug|Win32 {DEB40EF0-E215-4C2F-A0AD-3742E2E01A8C}.Tests FinalAlertDebug YR|Win32.Build.0 = Debug|Win32 + {DEB40EF0-E215-4C2F-A0AD-3742E2E01A8C}.Tests FinalAlertDebug YR|x64.ActiveCfg = Debug|x64 + {DEB40EF0-E215-4C2F-A0AD-3742E2E01A8C}.Tests FinalAlertDebug YR|x64.Build.0 = Debug|x64 + {5E445578-CB45-4D82-9A1C-FC7D3E8D866A}.Debug|Win32.ActiveCfg = Debug|Win32 + {5E445578-CB45-4D82-9A1C-FC7D3E8D866A}.Debug|Win32.Build.0 = Debug|Win32 + {5E445578-CB45-4D82-9A1C-FC7D3E8D866A}.Debug|x64.ActiveCfg = Debug|x64 + {5E445578-CB45-4D82-9A1C-FC7D3E8D866A}.Debug|x64.Build.0 = Debug|x64 {5E445578-CB45-4D82-9A1C-FC7D3E8D866A}.FinalAlertDebug YR|Win32.ActiveCfg = DebugMinimal|Win32 {5E445578-CB45-4D82-9A1C-FC7D3E8D866A}.FinalAlertDebug YR|Win32.Build.0 = DebugMinimal|Win32 + {5E445578-CB45-4D82-9A1C-FC7D3E8D866A}.FinalAlertDebug YR|x64.ActiveCfg = DebugMinimal|x64 + {5E445578-CB45-4D82-9A1C-FC7D3E8D866A}.FinalAlertDebug YR|x64.Build.0 = DebugMinimal|x64 {5E445578-CB45-4D82-9A1C-FC7D3E8D866A}.FinalAlertDebug|Win32.ActiveCfg = DebugMinimal|Win32 {5E445578-CB45-4D82-9A1C-FC7D3E8D866A}.FinalAlertDebug|Win32.Build.0 = DebugMinimal|Win32 + {5E445578-CB45-4D82-9A1C-FC7D3E8D866A}.FinalAlertDebug|x64.ActiveCfg = Debug|x64 + {5E445578-CB45-4D82-9A1C-FC7D3E8D866A}.FinalAlertDebug|x64.Build.0 = Debug|x64 {5E445578-CB45-4D82-9A1C-FC7D3E8D866A}.FinalAlertRelease YR|Win32.ActiveCfg = ReleaseMinimal|Win32 {5E445578-CB45-4D82-9A1C-FC7D3E8D866A}.FinalAlertRelease YR|Win32.Build.0 = ReleaseMinimal|Win32 + {5E445578-CB45-4D82-9A1C-FC7D3E8D866A}.FinalAlertRelease YR|x64.ActiveCfg = Release|x64 + {5E445578-CB45-4D82-9A1C-FC7D3E8D866A}.FinalAlertRelease YR|x64.Build.0 = Release|x64 {5E445578-CB45-4D82-9A1C-FC7D3E8D866A}.FinalAlertRelease|Win32.ActiveCfg = ReleaseMinimal|Win32 {5E445578-CB45-4D82-9A1C-FC7D3E8D866A}.FinalAlertRelease|Win32.Build.0 = ReleaseMinimal|Win32 + {5E445578-CB45-4D82-9A1C-FC7D3E8D866A}.FinalAlertRelease|x64.ActiveCfg = Release|x64 + {5E445578-CB45-4D82-9A1C-FC7D3E8D866A}.FinalAlertRelease|x64.Build.0 = Release|x64 {5E445578-CB45-4D82-9A1C-FC7D3E8D866A}.FinalSunDebug|Win32.ActiveCfg = DebugMinimal|Win32 {5E445578-CB45-4D82-9A1C-FC7D3E8D866A}.FinalSunDebug|Win32.Build.0 = DebugMinimal|Win32 + {5E445578-CB45-4D82-9A1C-FC7D3E8D866A}.FinalSunDebug|x64.ActiveCfg = Debug|x64 + {5E445578-CB45-4D82-9A1C-FC7D3E8D866A}.FinalSunDebug|x64.Build.0 = Debug|x64 {5E445578-CB45-4D82-9A1C-FC7D3E8D866A}.FinalSunRelease|Win32.ActiveCfg = ReleaseMinimal|Win32 {5E445578-CB45-4D82-9A1C-FC7D3E8D866A}.FinalSunRelease|Win32.Build.0 = ReleaseMinimal|Win32 + {5E445578-CB45-4D82-9A1C-FC7D3E8D866A}.FinalSunRelease|x64.ActiveCfg = Release|x64 + {5E445578-CB45-4D82-9A1C-FC7D3E8D866A}.FinalSunRelease|x64.Build.0 = Release|x64 + {5E445578-CB45-4D82-9A1C-FC7D3E8D866A}.Release|Win32.ActiveCfg = Release|Win32 + {5E445578-CB45-4D82-9A1C-FC7D3E8D866A}.Release|Win32.Build.0 = Release|Win32 + {5E445578-CB45-4D82-9A1C-FC7D3E8D866A}.Release|x64.ActiveCfg = Release|x64 + {5E445578-CB45-4D82-9A1C-FC7D3E8D866A}.Release|x64.Build.0 = Release|x64 {5E445578-CB45-4D82-9A1C-FC7D3E8D866A}.Template|Win32.ActiveCfg = ReleaseMinimal|Win32 {5E445578-CB45-4D82-9A1C-FC7D3E8D866A}.Template|Win32.Build.0 = ReleaseMinimal|Win32 + {5E445578-CB45-4D82-9A1C-FC7D3E8D866A}.Template|x64.ActiveCfg = DebugMinimal|x64 + {5E445578-CB45-4D82-9A1C-FC7D3E8D866A}.Template|x64.Build.0 = DebugMinimal|x64 {5E445578-CB45-4D82-9A1C-FC7D3E8D866A}.Tests FinalAlertDebug YR|Win32.ActiveCfg = DebugMinimal|Win32 {5E445578-CB45-4D82-9A1C-FC7D3E8D866A}.Tests FinalAlertDebug YR|Win32.Build.0 = DebugMinimal|Win32 + {5E445578-CB45-4D82-9A1C-FC7D3E8D866A}.Tests FinalAlertDebug YR|x64.ActiveCfg = Debug|x64 + {5E445578-CB45-4D82-9A1C-FC7D3E8D866A}.Tests FinalAlertDebug YR|x64.Build.0 = Debug|x64 + {75E18879-7564-4A2C-8C00-393A5A17171F}.Debug|Win32.ActiveCfg = Debug|Win32 + {75E18879-7564-4A2C-8C00-393A5A17171F}.Debug|Win32.Build.0 = Debug|Win32 + {75E18879-7564-4A2C-8C00-393A5A17171F}.Debug|x64.ActiveCfg = Debug|x64 + {75E18879-7564-4A2C-8C00-393A5A17171F}.Debug|x64.Build.0 = Debug|x64 + {75E18879-7564-4A2C-8C00-393A5A17171F}.FinalAlertDebug YR|Win32.ActiveCfg = Debug|Win32 + {75E18879-7564-4A2C-8C00-393A5A17171F}.FinalAlertDebug YR|Win32.Build.0 = Debug|Win32 + {75E18879-7564-4A2C-8C00-393A5A17171F}.FinalAlertDebug YR|x64.ActiveCfg = Debug|x64 + {75E18879-7564-4A2C-8C00-393A5A17171F}.FinalAlertDebug YR|x64.Build.0 = Debug|x64 + {75E18879-7564-4A2C-8C00-393A5A17171F}.FinalAlertDebug|Win32.ActiveCfg = Debug|Win32 + {75E18879-7564-4A2C-8C00-393A5A17171F}.FinalAlertDebug|Win32.Build.0 = Debug|Win32 + {75E18879-7564-4A2C-8C00-393A5A17171F}.FinalAlertDebug|x64.ActiveCfg = Debug|x64 + {75E18879-7564-4A2C-8C00-393A5A17171F}.FinalAlertDebug|x64.Build.0 = Debug|x64 + {75E18879-7564-4A2C-8C00-393A5A17171F}.FinalAlertRelease YR|Win32.ActiveCfg = Release|Win32 + {75E18879-7564-4A2C-8C00-393A5A17171F}.FinalAlertRelease YR|Win32.Build.0 = Release|Win32 + {75E18879-7564-4A2C-8C00-393A5A17171F}.FinalAlertRelease YR|x64.ActiveCfg = Release|x64 + {75E18879-7564-4A2C-8C00-393A5A17171F}.FinalAlertRelease YR|x64.Build.0 = Release|x64 + {75E18879-7564-4A2C-8C00-393A5A17171F}.FinalAlertRelease|Win32.ActiveCfg = Release|Win32 + {75E18879-7564-4A2C-8C00-393A5A17171F}.FinalAlertRelease|Win32.Build.0 = Release|Win32 + {75E18879-7564-4A2C-8C00-393A5A17171F}.FinalAlertRelease|x64.ActiveCfg = Release|x64 + {75E18879-7564-4A2C-8C00-393A5A17171F}.FinalAlertRelease|x64.Build.0 = Release|x64 + {75E18879-7564-4A2C-8C00-393A5A17171F}.FinalSunDebug|Win32.ActiveCfg = Debug|Win32 + {75E18879-7564-4A2C-8C00-393A5A17171F}.FinalSunDebug|Win32.Build.0 = Debug|Win32 + {75E18879-7564-4A2C-8C00-393A5A17171F}.FinalSunDebug|x64.ActiveCfg = Debug|x64 + {75E18879-7564-4A2C-8C00-393A5A17171F}.FinalSunDebug|x64.Build.0 = Debug|x64 + {75E18879-7564-4A2C-8C00-393A5A17171F}.FinalSunRelease|Win32.ActiveCfg = Release|Win32 + {75E18879-7564-4A2C-8C00-393A5A17171F}.FinalSunRelease|Win32.Build.0 = Release|Win32 + {75E18879-7564-4A2C-8C00-393A5A17171F}.FinalSunRelease|x64.ActiveCfg = Release|x64 + {75E18879-7564-4A2C-8C00-393A5A17171F}.FinalSunRelease|x64.Build.0 = Release|x64 + {75E18879-7564-4A2C-8C00-393A5A17171F}.Release|Win32.ActiveCfg = Release|Win32 + {75E18879-7564-4A2C-8C00-393A5A17171F}.Release|Win32.Build.0 = Release|Win32 + {75E18879-7564-4A2C-8C00-393A5A17171F}.Release|x64.ActiveCfg = Release|x64 + {75E18879-7564-4A2C-8C00-393A5A17171F}.Release|x64.Build.0 = Release|x64 + {75E18879-7564-4A2C-8C00-393A5A17171F}.Template|Win32.ActiveCfg = Debug|Win32 + {75E18879-7564-4A2C-8C00-393A5A17171F}.Template|Win32.Build.0 = Debug|Win32 + {75E18879-7564-4A2C-8C00-393A5A17171F}.Template|x64.ActiveCfg = Debug|x64 + {75E18879-7564-4A2C-8C00-393A5A17171F}.Template|x64.Build.0 = Debug|x64 + {75E18879-7564-4A2C-8C00-393A5A17171F}.Tests FinalAlertDebug YR|Win32.ActiveCfg = Debug|Win32 + {75E18879-7564-4A2C-8C00-393A5A17171F}.Tests FinalAlertDebug YR|Win32.Build.0 = Debug|Win32 + {75E18879-7564-4A2C-8C00-393A5A17171F}.Tests FinalAlertDebug YR|x64.ActiveCfg = Debug|x64 + {75E18879-7564-4A2C-8C00-393A5A17171F}.Tests FinalAlertDebug YR|x64.Build.0 = Debug|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/MissionEditor/AITriggerAddDlg.cpp b/MissionEditor/AITriggerAddDlg.cpp index 5f1b6e8..4535c0e 100644 --- a/MissionEditor/AITriggerAddDlg.cpp +++ b/MissionEditor/AITriggerAddDlg.cpp @@ -71,9 +71,10 @@ BOOL CAITriggerAddDlg::OnInitDialog() CListBox* lb=(CListBox*)GetDlgItem(IDC_AITRIGGERS); int i; - for(i=0;iAddString(*ai.sections["AITriggerTypes"].GetValueName(i)+ (CString)" " +GetParam(*ai.sections["AITriggerTypes"].GetValue(i), 0)); + for (i = 0; i < ai["AITriggerTypes"].Size(); i++) { + auto const& section = ai.GetSection("AITriggerTypes"); + auto const& valuePair = section.Nth(i); + lb->AddString(valuePair.first + (CString)" " + GetParam(valuePair.second, 0)); } return TRUE; // return TRUE unless you set the focus to a control diff --git a/MissionEditor/AITriggerTypes.cpp b/MissionEditor/AITriggerTypes.cpp index 8e2b6fd..a5ebe09 100644 --- a/MissionEditor/AITriggerTypes.cpp +++ b/MissionEditor/AITriggerTypes.cpp @@ -151,122 +151,26 @@ END_MESSAGE_MAP() void ListObjects(CComboBox& cb) { - CComboBox& m_UnitType=cb; - CIniFile& ini=Map->GetIniFile(); + CComboBox& m_UnitType = cb; + CIniFile& ini = Map->GetIniFile(); - int i; + auto addToUnitTypeByIni = [&m_UnitType](CIniFile& ini, const CString& sectionName) { + for (auto const& item : ini.GetSection(sectionName)) { + auto const& type = item.second; + auto const desc = type + + " (" + Map->GetUnitName(type) + ")"; + m_UnitType.AddString(desc); + } + }; + auto addToUnitType = [&ini, &addToUnitTypeByIni](const CString& sectionName) { + addToUnitTypeByIni(rules, sectionName); + addToUnitTypeByIni(ini, sectionName); + }; - CString ss="InfantryTypes"; - for(i=0;iGetUnitName((char*)(LPCTSTR)type); - - s+=")"; - m_UnitType.AddString(s); - } - for(i=0;iGetUnitName((char*)(LPCTSTR)type); - - s+=")"; - m_UnitType.AddString(s); - } - - ss="VehicleTypes"; - for(i=0;iGetUnitName((char*)(LPCTSTR)type); - - s+=")"; - m_UnitType.AddString(s); - } - for(i=0;iGetUnitName((char*)(LPCTSTR)type); - - s+=")"; - m_UnitType.AddString(s); - } - - ss="AircraftTypes"; - for(i=0;iGetUnitName((char*)(LPCTSTR)type); - - s+=")"; - m_UnitType.AddString(s); - } - for(i=0;iGetUnitName((char*)(LPCTSTR)type); - - s+=")"; - m_UnitType.AddString(s); - } - - ss="BuildingTypes"; - for(i=0;iGetUnitName((char*)(LPCTSTR)type); - - s+=")"; - m_UnitType.AddString(s); - } - for(i=0;iGetUnitName((char*)(LPCTSTR)type); - - s+=")"; - m_UnitType.AddString(s); - } + addToUnitType("InfantryTypes"); + addToUnitType("VehicleTypes"); + addToUnitType("AircraftTypes"); + addToUnitType("BuildingTypes"); } void CAITriggerTypes::UpdateDialog() @@ -347,9 +251,9 @@ void CAITriggerTypes::OnSelchangeAitriggertype() m_Enabled=FALSE; CIniFile& ini=Map->GetIniFile(); - if(ini.sections["AITriggerTypesEnable"].values.find((LPCTSTR)aitrigger)!=ini.sections["AITriggerTypesEnable"].values.end()) - if(stricmp(ini.sections["AITriggerTypesEnable"].values[(LPCTSTR)aitrigger], "yes")==NULL) - m_Enabled=TRUE; + if (ini.GetBool("AITriggerTypesEnable", aitrigger)) { + m_Enabled = TRUE; + } AITrigInfo info; info=ConvertToAITrigInfoFromHex((char*)(LPCSTR)aitt.data); @@ -541,34 +445,41 @@ void CAITriggerTypes::OnEnabled() UpdateData(); int sel=m_AITriggerType.GetCurSel(); - if(sel<0) return; - + if (sel < 0) { + return; + } CString aitrigger; m_AITriggerType.GetLBText(sel,aitrigger); TruncSpace(aitrigger); CIniFile& ini=Map->GetIniFile(); - if(m_Enabled) - { + if(m_Enabled) { // enable it - ini.sections["AITriggerTypesEnable"].values[(LPCTSTR)aitrigger]="yes"; + ini.SetBool("AITriggerTypesEnable", aitrigger, true); + } else { + if (auto const pSec = ini.TryGetSection("AITriggerTypesEnable")) { + pSec->RemoveByKey(aitrigger); + } } - else - ini.sections["AITriggerTypesEnable"].values.erase((LPCTSTR)aitrigger); } void CAITriggerTypes::SetAITriggerParam(const char *value, int param) { int sel=m_AITriggerType.GetCurSel(); - if(sel<0) return; + if (sel < 0) { + return; + } CString aitrigger; m_AITriggerType.GetLBText(sel,aitrigger); TruncSpace(aitrigger); CIniFile& ini=Map->GetIniFile(); - ini.sections["AITriggerTypes"].values[aitrigger]=SetParam(ini.sections["AITriggerTypes"].values[aitrigger],param,value); + + if (auto const pSec = ini.TryGetSection("AITriggerTypes")) { + pSec->SetString(aitrigger, SetParam(pSec->GetString(aitrigger), param, value)); + } } void CAITriggerTypes::OnAdd() @@ -578,12 +489,9 @@ void CAITriggerTypes::OnAdd() CString data="New AI Trigger,"; // now try to set a teamtype - if(ini.sections["TeamTypes"].values.size()>0) - { - data+=*ini.sections["TeamTypes"].GetValue(0); - } - else - { + if (ini["TeamTypes"].Size()>0) { + data+=*ini["TeamTypes"].Nth(0).second; + } else { data+=""; } @@ -599,18 +507,18 @@ void CAITriggerTypes::OnAdd() data+=",0000000000000000000000000000000000000000000000000000000000000000,50.000000,30.000000,50.000000,1,0,1,1,"; // a pool seems to need both teamtypes the same - if(ini.sections["TeamTypes"].values.size()>0) - { - data+="";//*ini.sections["TeamTypes"].GetValue(0); - } - else + //if(ini.sections["TeamTypes"].values.size()>0) + //{ + // data+="";//*ini.sections["TeamTypes"].GetValue(0); + //} + //else { data+=""; } data+=",1,1,1"; - ini.sections["AITriggerTypes"].values[ID]=data; + ini.SetString("AITriggerTypes", ID, data); UpdateDialog(); @@ -639,10 +547,10 @@ void CAITriggerTypes::OnDelete() m_AITriggerType.GetLBText(sel,aitrigger); TruncSpace(aitrigger); - CIniFile& ini=Map->GetIniFile(); + CIniFile& ini = Map->GetIniFile(); - ini.sections["AITriggerTypes"].values.erase(aitrigger); - ini.sections["AITriggerTypesEnable"].values.erase(aitrigger); + ini.RemoveValueByKey("AITriggerTypes", aitrigger); + ini.RemoveValueByKey("AITriggerTypesEnable", aitrigger); UpdateDialog(); } diff --git a/MissionEditor/AiTriggerTypesEnable.cpp b/MissionEditor/AiTriggerTypesEnable.cpp index f534b8b..de9b03e 100644 --- a/MissionEditor/AiTriggerTypesEnable.cpp +++ b/MissionEditor/AiTriggerTypesEnable.cpp @@ -80,29 +80,27 @@ void CAiTriggerTypesEnable::UpdateDialog() while(m_AITriggerType.DeleteString(0)!=CB_ERR); - CIniFile& ini=Map->GetIniFile(); + CIniFile& ini = Map->GetIniFile(); int i; - for(i=0;iGetIniFile(); int i; - for(i=0;i=0) aitrigger.SetAt(aitrigger.Find(" "), 0); + if (aitrigger.Find(" ") >= 0) { + aitrigger.SetAt(aitrigger.Find(" "), 0); + } CIniFile& ini=Map->GetIniFile(); - ini.sections["AITriggerTypesEnable"].values.erase((LPCTSTR)aitrigger); + ini.RemoveValueByKey("AITriggerTypesEnable", aitrigger); UpdateDialog(); } void CAiTriggerTypesEnable::OnAdd() { - - - //CString p=InputBox("Please enter the ID of the AITriggerType (for a list of all AITriggerType-IDs use the All-Section)","Enable AITriggerType"); + //CString newTriggerId=InputBox("Please enter the ID of the AITriggerType (for a list of all AITriggerType-IDs use the All-Section)","Enable AITriggerType"); CAITriggerAddDlg dlg; if(dlg.DoModal()==IDCANCEL) return; - CString p=dlg.m_AITrigger; - TruncSpace(p); - if(p.GetLength()==0) return; + CString newTriggerId = dlg.m_AITrigger; + TruncSpace(newTriggerId); + if (newTriggerId.GetLength() == 0) { + return; + } CIniFile& ini=Map->GetIniFile(); - ini.sections["AITriggerTypesEnable"].values[p]="yes"; + ini.SetBool("AITriggerTypesEnable", newTriggerId, true); UpdateDialog(); } diff --git a/MissionEditor/All.cpp b/MissionEditor/All.cpp index a95ce2c..9a2f9c2 100644 --- a/MissionEditor/All.cpp +++ b/MissionEditor/All.cpp @@ -95,11 +95,10 @@ void CAll::UpdateDialog() m_Value.SetWindowText(""); int i; - for(i=ini.sections.size()-1;i>=0;i--) - { - const CString* name=ini.GetSectionName(i); - if(!Map->IsMapSection(*name)) - m_Sections.InsertString(0, *name); + for (auto const& [name, sec] : ini) { + if (!Map->IsMapSection(name)) { + m_Sections.InsertString(-1, name); + } } m_Sections.SetCurSel(1); @@ -119,10 +118,8 @@ void CAll::OnSelchangeSections() int i; m_Keys.SetRedraw(FALSE); SetCursor(LoadCursor(0,IDC_WAIT)); - for(i=0;i=0)m_Keys.GetText(m_Keys.GetCurSel(), cuKey) ; + if (m_Keys.GetCurSel() >= 0) { + m_Keys.GetText(m_Keys.GetCurSel(), cuKey); + } - - - ini.sections[cuSection].values[cuKey]=t; + ini.SetString(cuSection, cuKey, t); } @@ -162,7 +159,7 @@ void CAll::OnSelchangeKeys() CString cuKey; m_Keys.GetText(m_Keys.GetCurSel(), cuKey) ; - m_Value.SetWindowText(ini.sections[cuSection].values[cuKey]); + m_Value.SetWindowText(ini.GetString(cuSection, cuKey)); } void CAll::OnUpdateValue() @@ -172,11 +169,11 @@ void CAll::OnUpdateValue() void CAll::OnAddsection() { - CString name=InputBox("Please set the name of the new section (the section may already exist)", "Insert Section"); + CString name = InputBox("Please set the name of the new section (the section may already exist)", "Insert Section"); - CIniFile& ini=Map->GetIniFile(); + CIniFile& ini = Map->GetIniFile(); - CIniFileSection stub=ini.sections[(LPCTSTR)name]; + ini.AddSection(name); UpdateDialog(); } @@ -187,7 +184,7 @@ void CAll::OnDeletesection() int cusection; cusection=m_Sections.GetCurSel(); - if(cusection==-1) { + if (cusection==-1) { MessageBox("You cannot delete a section without choosing one."); return; } @@ -195,9 +192,11 @@ void CAll::OnDeletesection() CString str; m_Sections.GetLBText(cusection, str); - if(MessageBox(CString((CString)"Are you sure you want to delete " + str + "? You should be really careful, you may not be able to use the map afterwards."), "Delete section", MB_YESNO)==IDNO) return; + if (MessageBox(CString((CString)"Are you sure you want to delete " + str + "? You should be really careful, you may not be able to use the map afterwards."), "Delete section", MB_YESNO) == IDNO) { + return; + } - ini.sections.erase(str); + ini.DeleteSection(str); UpdateDialog(); } @@ -220,9 +219,11 @@ void CAll::OnDeletekey() m_Sections.GetLBText(cuSection, sec); m_Keys.GetText(cukey, str); - if(MessageBox(CString((CString)"Are you sure you want to delete " + str + "? You should be really careful, you may not be able to use the map afterwards."), "Delete key", MB_YESNO)==IDNO) return; + if (MessageBox(CString((CString)"Are you sure you want to delete " + str + "? You should be really careful, you may not be able to use the map afterwards."), "Delete key", MB_YESNO) == IDNO) { + return; + } - ini.sections[sec].values.erase(str); + ini.RemoveValueByKey(sec, str); UpdateDialog(); @@ -246,15 +247,14 @@ void CAll::OnAddkey() CString key, value; key=InputBox("Please set the name and value for the current key here: (for example, setting a new key ""Strength"" with the value 200 can be written as ""Strength=200"". You don´t need to specify a value.)", "Create key"); - if(key.Find("=")!=-1) - { + if (key.Find("=") != -1) { // value specified // MW BUGFIX value=key.Right(key.GetLength()-key.Find("=")-1); key=key.Left(key.Find("=")); } - ini.sections[sec].values[key]=value; + ini.SetString(sec, key, value); UpdateDialog(); m_Sections.SetCurSel(cusection); diff --git a/MissionEditor/Basic.cpp b/MissionEditor/Basic.cpp index a9e84e9..f2f086c 100644 --- a/MissionEditor/Basic.cpp +++ b/MissionEditor/Basic.cpp @@ -122,41 +122,42 @@ void CBasic::UpdateDialog() { CIniFile& ini=Map->GetIniFile(); - m_AltNextScenario.SetWindowText(ini.sections["Basic"].values["AltNextScenario"]); - m_Name.SetWindowText(ini.sections["Basic"].values["Name"]); - m_CarryOverCap.SetWindowText(ini.sections["Basic"].values["CarryOverCap"]); - m_EndOfGame.SetWindowText(ini.sections["Basic"].values["EndOfGame"]); - m_FreeRadar.SetWindowText(ini.sections["Basic"].values["FreeRadar"]); - m_IceGrowthEnabled.SetWindowText(ini.sections["Basic"].values["IceGrowthEnabled"]); - m_IgnoreGlobalAITriggers.SetWindowText(ini.sections["Basic"].values["IgnoreGlobalAITriggers"]); - m_InitTime.SetWindowText(ini.sections["Basic"].values["InitTime"]); - m_MultiplayerOnly.SetWindowText(ini.sections["Basic"].values["MultiplayerOnly"]); - m_NewINIFormat.SetWindowText(ini.sections["Basic"].values["NewINIFormat"]); - m_NextScenario.SetWindowText(ini.sections["Basic"].values["NextScenario"]); - m_Official.SetWindowText(ini.sections["Basic"].values["Official"]); - m_OneTimeOnly.SetWindowText(ini.sections["Basic"].values["OneTimeOnly"]); - m_Percent.SetWindowText(ini.sections["Basic"].values["Percent"]); - m_SkipMapSelect.SetWindowText(ini.sections["Basic"].values["SkipMapSelect"]); - m_SkipScore.SetWindowText(ini.sections["Basic"].values["SkipScore"]); - m_TiberiumDeathToVisceroid.SetWindowText(ini.sections["Basic"].values["TiberiumDeathToVisceroid"]); - m_TiberiumGrowthEnabled.SetWindowText(ini.sections["Basic"].values["TiberiumGrowthEnabled"]); - m_TrainCrate.SetWindowText(ini.sections["Basic"].values["TrainCrate"]); - m_TruckCrate.SetWindowText(ini.sections["Basic"].values["TruckCrate"]); - m_VeinGrowthEnabled.SetWindowText(ini.sections["Basic"].values["VeinGrowthEnabled"]); + auto const& basicSec = ini["Basic"]; + m_AltNextScenario.SetWindowText(basicSec["AltNextScenario"]); + m_Name.SetWindowText(basicSec["Name"]); + m_CarryOverCap.SetWindowText(basicSec["CarryOverCap"]); + m_EndOfGame.SetWindowText(basicSec["EndOfGame"]); + m_FreeRadar.SetWindowText(basicSec["FreeRadar"]); + m_IceGrowthEnabled.SetWindowText(basicSec["IceGrowthEnabled"]); + m_IgnoreGlobalAITriggers.SetWindowText(basicSec["IgnoreGlobalAITriggers"]); + m_InitTime.SetWindowText(basicSec["InitTime"]); + m_MultiplayerOnly.SetWindowText(basicSec["MultiplayerOnly"]); + m_NewINIFormat.SetWindowText(basicSec["NewINIFormat"]); + m_NextScenario.SetWindowText(basicSec["NextScenario"]); + m_Official.SetWindowText(basicSec["Official"]); + m_OneTimeOnly.SetWindowText(basicSec["OneTimeOnly"]); + m_Percent.SetWindowText(basicSec["Percent"]); + m_SkipMapSelect.SetWindowText(basicSec["SkipMapSelect"]); + m_SkipScore.SetWindowText(basicSec["SkipScore"]); + m_TiberiumDeathToVisceroid.SetWindowText(basicSec["TiberiumDeathToVisceroid"]); + m_TiberiumGrowthEnabled.SetWindowText(basicSec["TiberiumGrowthEnabled"]); + m_TrainCrate.SetWindowText(basicSec["TrainCrate"]); + m_TruckCrate.SetWindowText(basicSec["TruckCrate"]); + m_VeinGrowthEnabled.SetWindowText(basicSec["VeinGrowthEnabled"]); - if(ini.sections["Basic"].values.find("RequiredAddOn")!=ini.sections["Basic"].values.end()) - { - m_RequiredAddOn.SetWindowText(ini.sections["Basic"].values["RequiredAddOn"]); - } - else + auto const& addOn = basicSec.GetString("RequiredAddOn"); + if (!addOn.IsEmpty()) { + m_RequiredAddOn.SetWindowText(addOn); + } else { m_RequiredAddOn.SetWindowText("0"); + } } void CBasic::OnChangeName() { CIniFile& ini=Map->GetIniFile(); - ini.sections["Basic"].values["Name"]=GetText(&m_Name); + ini.SetString("Basic", "Name", GetText(&m_Name)); } void CBasic::UpdateData() @@ -170,121 +171,121 @@ void CBasic::UpdateData() void CBasic::OnEditchangeNextscenario() { CIniFile& ini=Map->GetIniFile(); - ini.sections["Basic"].values["NextScenario"]=GetText(&m_NextScenario); + ini.SetString("Basic", "NextScenario", GetText(&m_NextScenario)); } void CBasic::OnEditchangeAltnextscenario() { CIniFile& ini=Map->GetIniFile(); - ini.sections["Basic"].values["AltNextScenario"]=GetText(&m_AltNextScenario); + ini.SetString("Basic", "AltNextScenario", GetText(&m_AltNextScenario)); } void CBasic::OnChangeNewiniformat() { CIniFile& ini=Map->GetIniFile(); - ini.sections["Basic"].values["NewINIFormat"]=GetText(&m_NewINIFormat); + ini.SetString("Basic", "NewINIFormat", GetText(&m_NewINIFormat)); } void CBasic::OnChangeCarryovercap() { CIniFile& ini=Map->GetIniFile(); - ini.sections["Basic"].values["CarryOverCap"]=GetText(&m_CarryOverCap); + ini.SetString("Basic", "CarryOverCap", GetText(&m_CarryOverCap)); } void CBasic::OnEditchangeEndofgame() { CIniFile& ini=Map->GetIniFile(); - ini.sections["Basic"].values["EndOfGame"]=GetText(&m_EndOfGame); + ini.SetString("Basic", "EndOfGame", GetText(&m_EndOfGame)); } void CBasic::OnEditchangeSkipscore() { CIniFile& ini=Map->GetIniFile(); - ini.sections["Basic"].values["SkipScore"]=GetText(&m_SkipScore); + ini.SetString("Basic", "SkipScore", GetText(&m_SkipScore)); } void CBasic::OnEditchangeOnetimeonly() { CIniFile& ini=Map->GetIniFile(); - ini.sections["Basic"].values["OneTimeOnly"]=GetText(&m_OneTimeOnly); + ini.SetString("Basic", "OneTimeOnly", GetText(&m_OneTimeOnly)); } void CBasic::OnEditchangeSkipmapselect() { CIniFile& ini=Map->GetIniFile(); - ini.sections["Basic"].values["SkipMapSelect"]=GetText(&m_SkipMapSelect); + ini.SetString("Basic", "SkipMapSelect", GetText(&m_SkipMapSelect)); } void CBasic::OnEditchangeOfficial() { CIniFile& ini=Map->GetIniFile(); - ini.sections["Basic"].values["Official"]=GetText(&m_Official); + ini.SetString("Basic", "Official", GetText(&m_Official)); } void CBasic::OnEditchangeIgnoreglobalaitriggers() { CIniFile& ini=Map->GetIniFile(); - ini.sections["Basic"].values["IgnoreGlobalAITriggers"]=GetText(&m_IgnoreGlobalAITriggers); + ini.SetString("Basic", "IgnoreGlobalAITriggers", GetText(&m_IgnoreGlobalAITriggers)); } void CBasic::OnEditchangeTruckcrate() { CIniFile& ini=Map->GetIniFile(); - ini.sections["Basic"].values["TruckCrate"]=GetText(&m_TruckCrate); + ini.SetString("Basic", "TruckCrate", GetText(&m_TruckCrate)); } void CBasic::OnEditchangeTraincrate() { CIniFile& ini=Map->GetIniFile(); - ini.sections["Basic"].values["TrainCrate"]=GetText(&m_TrainCrate); + ini.SetString("Basic", "TrainCrate", GetText(&m_TrainCrate)); } void CBasic::OnChangePercent() { CIniFile& ini=Map->GetIniFile(); - ini.sections["Basic"].values["Percent"]=GetText(&m_Percent); + ini.SetString("Basic", "Percent", GetText(&m_Percent)); } void CBasic::OnChangeMultiplayeronly() { CIniFile& ini=Map->GetIniFile(); - ini.sections["Basic"].values["MultiplayerOnly"]=GetText(&m_MultiplayerOnly); + ini.SetString("Basic", "MultiplayerOnly", GetText(&m_MultiplayerOnly)); } void CBasic::OnEditchangeTiberiumgrowthenabled() { CIniFile& ini=Map->GetIniFile(); - ini.sections["Basic"].values["TiberiumGrowthEnabled"]=GetText(&m_TiberiumGrowthEnabled); + ini.SetString("Basic", "TiberiumGrowthEnabled", GetText(&m_TiberiumGrowthEnabled)); } void CBasic::OnEditchangeVeingrowthenabled() { CIniFile& ini=Map->GetIniFile(); - ini.sections["Basic"].values["VeinGrowthEnabled"]=GetText(&m_VeinGrowthEnabled); + ini.SetString("Basic", "VeinGrowthEnabled", GetText(&m_VeinGrowthEnabled)); } void CBasic::OnEditchangeIcegrowthenabled() { CIniFile& ini=Map->GetIniFile(); - ini.sections["Basic"].values["IceGrowthEnabled"]=GetText(&m_IceGrowthEnabled); + ini.SetString("Basic", "IceGrowthEnabled", GetText(&m_IceGrowthEnabled)); } void CBasic::OnEditchangeTiberiumdeathtovisceroid() { CIniFile& ini=Map->GetIniFile(); - ini.sections["Basic"].values["TiberiumDeathToVisceroid"]=GetText(&m_TiberiumDeathToVisceroid); + ini.SetString("Basic", "TiberiumDeathToVisceroid", GetText(&m_TiberiumDeathToVisceroid)); } void CBasic::OnEditchangeFreeradar() { CIniFile& ini=Map->GetIniFile(); - ini.sections["Basic"].values["FreeRadar"]=GetText(&m_FreeRadar); + ini.SetString("Basic", "FreeRadar", GetText(&m_FreeRadar)); } void CBasic::OnChangeInittime() { CIniFile& ini=Map->GetIniFile(); - ini.sections["Basic"].values["InitTime"]=GetText(&m_InitTime); + ini.SetString("Basic", "InitTime", GetText(&m_InitTime)); } void CBasic::UpdateStrings() @@ -333,9 +334,11 @@ void CBasic::UpdateStrings() void CBasic::OnEditchangeRequiredaddon() { - CIniFile& ini=Map->GetIniFile(); - ini.sections["Basic"].values["RequiredAddOn"]=GetText(&m_RequiredAddOn); - if(ini.sections["Basic"].values["RequiredAddOn"]=="0") ini.sections["Basic"].values.erase("RequiredAddOn"); + CIniFile& ini = Map->GetIniFile(); + ini.SetString("Basic", "RequiredAddOn", GetText(&m_RequiredAddOn)); + if (ini.GetInteger("Basic", "RequiredAddOn") == 0) { + ini.RemoveValueByKey("Basic", "RequiredAddOn"); + } } diff --git a/MissionEditor/Bitmap2MapConverter.cpp b/MissionEditor/Bitmap2MapConverter.cpp index 6dfa91b..009f039 100644 --- a/MissionEditor/Bitmap2MapConverter.cpp +++ b/MissionEditor/Bitmap2MapConverter.cpp @@ -102,12 +102,12 @@ BOOL CBitmap2MapConverter::Convert(HBITMAP hBitmap, CMapData & mapdata) int water_start=i+8; // to 12 - int sandset=atoi((*tiles).sections["General"].values["SandTile"]); - int greenset=atoi((*tiles).sections["General"].values["GreenTile"]); + int sandset = tiles->GetInteger("General", "SandTile"); + int greenset= tiles->GetInteger("General", "GreenTile"); #ifdef RA2_MODE - sandset=atoi((*tiles).sections["General"].values["GreenTile"]); - greenset=atoi((*tiles).sections["General"].values["RoughTile"]); + sandset = tiles->GetInteger("General", "GreenTile"); + greenset = tiles->GetInteger("General", "RoughTile"); #endif for(i=0;i<(*tiledata_count);i++) diff --git a/MissionEditor/Building.cpp b/MissionEditor/Building.cpp index 63e72a2..1a55d95 100644 --- a/MissionEditor/Building.cpp +++ b/MissionEditor/Building.cpp @@ -95,14 +95,7 @@ END_MESSAGE_MAP() CString GetName(CString id) { - CIniFile& ini=Map->GetIniFile(); - if(ini.sections.find(id)!=ini.sections.end()) - { - if(ini.sections[id].values.find("Name")!=ini.sections[id].values.end()) - return ini.sections[id].values["Name"]; - - } - return rules.sections[id].values["Name"]; + return rules.GetString(id, "Name"); } void CBuilding::OnOK() @@ -152,93 +145,28 @@ BOOL CBuilding::OnInitDialog() UpdateData(FALSE); int upgradecount=0; - if(strcmp(m_type,"GACTWR")==NULL) - upgradecount=1; - - - if(ini.sections.find(m_type)!=ini.sections.end()) - { - if(ini.sections[m_type].values.find("Upgrades")!=ini.sections[m_type].values.end()) - { - // ok we have our upgrade - upgradecount=atoi(ini.sections[m_type].values["Upgrades"]); - } - else - { - if(rules.sections[m_type].values.find("Upgrades")!=rules.sections[m_type].values.end()) - upgradecount=atoi(rules.sections[m_type].values["Upgrades"]); - } - } - else - { - if(rules.sections[m_type].values.find("Upgrades")!=rules.sections[m_type].values.end()) - upgradecount=atoi(rules.sections[m_type].values["Upgrades"]); + if (strcmp(m_type, "GACTWR") == NULL) { + upgradecount = 1; } + upgradecount = ini.GetInteger(m_type, "Upgrades"); GetDlgItem(IDC_P5)->SendMessage(CB_SETCURSEL, atoi(m_spotlight), 0); - if(upgradecount>0) - { - for(i=0;iAddString(((CString)unitname+" ("+GetName(unitname)+")")); - ((CComboBox*)GetDlgItem(IDC_P7))->AddString(((CString)unitname+" ("+GetName(unitname)+")")); - ((CComboBox*)GetDlgItem(IDC_P8))->AddString(((CString)unitname+" ("+GetName(unitname)+")")); - } + if (upgradecount > 0) { + auto updatePowerupItems = [=](const CIniFile& ini) { + for (auto const& [seq, unitname] : ini["BuildingTypes"]) { + auto const& targetBldID = ini.GetString(unitname, "PowersUpBuilding"); + if (targetBldID == m_type) { + auto const desc = unitname + " (" + GetName(unitname) + ")"; + ((CComboBox*)GetDlgItem(IDC_P6))->AddString(desc); + ((CComboBox*)GetDlgItem(IDC_P7))->AddString(desc); + ((CComboBox*)GetDlgItem(IDC_P8))->AddString(desc); } } - else - { - // ini did not specify thing specified - if(rules.sections[unitname].values.find("PowersUpBuilding")!=rules.sections[unitname].values.end()) - { - // rules file specified new PowersUpBuilding - if(_stricmp(rules.sections[unitname].values["PowersUpBuilding"], m_type)==NULL) - { - ((CComboBox*)GetDlgItem(IDC_P6))->AddString(((CString)unitname+" ("+GetName(unitname)+")")); - ((CComboBox*)GetDlgItem(IDC_P7))->AddString(((CString)unitname+" ("+GetName(unitname)+")")); - ((CComboBox*)GetDlgItem(IDC_P8))->AddString(((CString)unitname+" ("+GetName(unitname)+")")); - } - } - } - } - if(ini.sections.find("BuildingTypes")!=ini.sections.end()) - { - for(i=0;iAddString(((CString)unitname+" ("+GetName(unitname)+")")); - ((CComboBox*)GetDlgItem(IDC_P7))->AddString(((CString)unitname+" ("+GetName(unitname)+")")); - ((CComboBox*)GetDlgItem(IDC_P8))->AddString(((CString)unitname+" ("+GetName(unitname)+")")); - } - } - } - - } - } + }; + updatePowerupItems(rules); + updatePowerupItems(ini); } GetDlgItem(IDC_P8)->EnableWindow(TRUE); diff --git a/MissionEditor/CellTag.cpp b/MissionEditor/CellTag.cpp index c310168..ba036cc 100644 --- a/MissionEditor/CellTag.cpp +++ b/MissionEditor/CellTag.cpp @@ -74,7 +74,7 @@ BOOL CCellTag::OnInitDialog() CComboBox& m_Tag=*((CComboBox*)GetDlgItem(IDC_TAG)); - if(ini.sections.find("Tags")==ini.sections.end()) + if(!ini.TryGetSection("Tags")) { MessageBox("No tags are specified."); OnCancel(); @@ -82,7 +82,9 @@ BOOL CCellTag::OnInitDialog() else { ListTags(m_Tag, FALSE); - if(m_tag=="") m_Tag.SetCurSel(0); + if (m_tag == "") { + m_Tag.SetCurSel(0); + } } UpdateStrings(); diff --git a/MissionEditor/CliffModifier.cpp b/MissionEditor/CliffModifier.cpp index bfa86d8..5480bbf 100644 --- a/MissionEditor/CliffModifier.cpp +++ b/MissionEditor/CliffModifier.cpp @@ -310,12 +310,14 @@ DWORD CCliffModifier::GetTileToPlace(DWORD dwPos, BOOL* bSmall) } - CString sec=GetDataSection(); - CIniFile& ini=Map->GetIniFile(); - if(g_data.sections.find(sec+ini.sections["Map"].values["Theater"])!=g_data.sections.end()) - sec=sec+ini.sections["Map"].values["Theater"]; + CString sec = GetDataSection(); + CIniFile& ini = Map->GetIniFile(); + auto const& theaterID = g_data.GetString("Map", "Theater"); + if (!theaterID.IsEmpty()) { + sec += theaterID; + } - count=atoi(g_data.sections[sec].values[type+"c"]); + count = g_data.GetInteger(sec, type + "c"); @@ -339,7 +341,7 @@ DWORD CCliffModifier::GetTileToPlace(DWORD dwPos, BOOL* bSmall) itoa(i, c, 10); CString cur=type; cur+=c; - notusedascliff[dwStartSet+atoi(g_data.sections[sec].values[cur])]=TRUE; + notusedascliff[dwStartSet + g_data.GetInteger(sec, cur)] = TRUE; } CString corner_searched=""; @@ -373,17 +375,13 @@ DWORD CCliffModifier::GetTileToPlace(DWORD dwPos, BOOL* bSmall) if(corner_searched.GetLength()>0) break; } - BOOL bCornerFound=FALSE; - if(g_data.sections[sec].FindName(type+corner_searched+"c")>=0) - { - int icount=atoi(g_data.sections[sec].values[type+corner_searched+"c"]); - if(icount) - { - bCornerFound=TRUE; - count=icount; - } + BOOL bCornerFound = FALSE;; + if (int icount = g_data.GetInteger(sec, type + corner_searched + "c")) { + bCornerFound = TRUE; + count = icount; } + if(!bCornerFound) corner_searched=""; if(count==0) return -1; @@ -395,11 +393,10 @@ DWORD CCliffModifier::GetTileToPlace(DWORD dwPos, BOOL* bSmall) DWORD dwDY=m_dwTo/Map->GetIsoSize(); - for(i=0;isections["General"].values["WaterCliffs"]); - if(m_bAlternative) watercliffs=cliffwater2set; + int watercliffs = tiles->GetInteger("General", "WaterCliffs"); + if (m_bAlternative) { + watercliffs = cliffwater2set; + } itoa(watercliffs, 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()) return useables[k]; + auto const pSec = tiles->TryGetSection(sec); + if (!pSec) { + return useables[k]; + } - if(atoi(tiles->sections[sec].values["TilesInSet"])>useables[k]-dwStartSet) - { + if (pSec->GetInteger("TilesInSet") > useables[k] - dwStartSet) { DWORD dwStartWaterSet=0; for(i=0;i<(*tiledata_count);i++) { diff --git a/MissionEditor/FinalSun.cpp b/MissionEditor/FinalSun.cpp index 1f5424c..3b2dbe6 100644 --- a/MissionEditor/FinalSun.cpp +++ b/MissionEditor/FinalSun.cpp @@ -188,8 +188,7 @@ BOOL CFinalSunApp::InitInstance() #endif language.LoadFile(languagefile); - if (language.sections.size() == 0) - { + if (language.Size() == 0) { MessageBox(0, "FALanguage.ini does not exist or is not valid (download corrupt?)", "", 0); exit(0); } @@ -233,122 +232,128 @@ BOOL CFinalSunApp::InitInstance() auto& opts = m_Options; - HKEY hKey = 0; - int res; - res = RegOpenKeyExW(HKEY_LOCAL_MACHINE, key.c_str(), 0, KEY_EXECUTE/*KEY_ALL_ACCESS*/, &hKey); - if (res != ERROR_SUCCESS) - { - std::wstring s = L"Failed to access registry. Using manual setting. Error was:\n"; - wchar_t c[1024] = { 0 }; - FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM, 0, res, 0, c, 1023, NULL); - MessageBoxW(0, (s + c).c_str(), L"Error", 0); - opts.TSExe = optini.sections[game].values["Exe"]; - } - else - { - // key opened - wchar_t path[MAX_PATH + 1] = { 0 }; - DWORD pathsize = MAX_PATH; - DWORD type = REG_SZ; - if ((res = RegQueryValueExW(hKey, L"InstallPath", 0, &type, (unsigned char*)path, &pathsize)) != ERROR_SUCCESS) - { - std::wstring s = L"Failed to access registry. Using manual setting. Error was:\n"; - wchar_t c[1024] = { 0 }; - FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM, 0, res, 0, c, 1023, NULL); - MessageBoxW(0, (s + c).c_str(), L"Error", 0); - opts.TSExe = optini.sections[game].values["Exe"]; - } - else + // TODO: use config + auto getPathFromRegistry = false; + auto getPathFromIni = true; + + if (getPathFromRegistry) { + do { + int res; + HKEY hKey = 0; + res = RegOpenKeyExW(HKEY_LOCAL_MACHINE, key.c_str(), 0, KEY_EXECUTE/*KEY_ALL_ACCESS*/, &hKey); + if (res != ERROR_SUCCESS) { + getPathFromIni = true; + std::wstring s = L"Failed to access registry. Using manual setting. Error was:\n"; + wchar_t c[1024] = { 0 }; + FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM, 0, res, 0, c, 1023, NULL); + MessageBoxW(0, (s + c).c_str(), L"Error", 0); + break; + } + // key opened + wchar_t path[MAX_PATH + 1] = { 0 }; + DWORD pathsize = MAX_PATH; + DWORD type = REG_SZ; + if ((res = RegQueryValueExW(hKey, L"InstallPath", 0, &type, (unsigned char*)path, &pathsize)) != ERROR_SUCCESS) { + getPathFromIni = true; + std::wstring s = L"Failed to access registry. Using manual setting. Error was:\n"; + wchar_t c[1024] = { 0 }; + FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM, 0, res, 0, c, 1023, NULL); + MessageBoxW(0, (s + c).c_str(), L"Error", 0); + break; + } opts.TSExe = path; + } while (0); } + if (getPathFromIni) { + opts.TSExe = optini.GetString(game, "Exe"); + } + auto const& appSec = optini[app]; if (copiedDefaultFile || - optini.sections.size() == 0 || - opts.TSExe.GetLength() == 0 || - optini.sections[app].values["Language"].GetLength() == 0 || - optini.sections[app].values.find("FileSearchLikeGame") == optini.sections[app].values.end() || - optini.sections[app].values.find("PreferLocalTheaterFiles") == optini.sections[app].values.end()) - { + optini.Size() == 0 || + opts.TSExe.IsEmpty() || + appSec.GetString( "Language").IsEmpty() || + !appSec.GetBool("FileSearchLikeGame") || + !appSec.GetBool("PreferLocalTheaterFiles")) { opts.bSearchLikeTS = TRUE; bOptionsStartup = TRUE; ShowOptionsDialog(); bOptionsStartup = FALSE; - } - else - { - opts.LanguageName = optini.sections[app].values["Language"]; - if (optini.sections[app].values["FileSearchLikeGame"] != "no") + } else { + opts.LanguageName = appSec.GetString("Language"); + if (appSec.GetBool("FileSearchLikeGame")) { opts.bSearchLikeTS = TRUE; - else opts.bSearchLikeTS = FALSE; + } + else { + opts.bSearchLikeTS = FALSE; + } } - opts.bPreferLocalTheaterFiles = optini.sections[app].values.emplace("PreferLocalTheaterFiles", opts.bPreferLocalTheaterFiles ? "1" : "0").first->second == "1"; + opts.bPreferLocalTheaterFiles = appSec.GetBool("PreferLocalTheaterFiles", opts.bPreferLocalTheaterFiles); + auto const& graphSec = optini["Graphics"]; + opts.bDoNotLoadAircraftGraphics = graphSec.GetBool("NoAircraftGraphics"); + opts.bDoNotLoadVehicleGraphics = graphSec.GetBool("NoVehicleGraphics"); + opts.bDoNotLoadBuildingGraphics = graphSec.GetBool("NoBuildingGraphics"); + opts.bDoNotLoadInfantryGraphics = graphSec.GetBool("NoInfantryGraphics"); + opts.bDoNotLoadTreeGraphics = graphSec.GetBool("NoTreeGraphics"); + opts.bDoNotLoadSnowGraphics = graphSec.GetBool("NoSnowGraphics"); + opts.bDoNotLoadTemperateGraphics = graphSec.GetBool("NoTemperateGraphics"); + opts.bDoNotLoadBMPs = graphSec.GetBool("NoBMPs"); + opts.bDoNotLoadOverlayGraphics = graphSec.GetBool("NoOverlayGraphics"); + opts.bVSync = graphSec.GetBool("VSync", opts.bVSync); - opts.bDoNotLoadAircraftGraphics = optini.sections["Graphics"].values["NoAircraftGraphics"] == "1"; - opts.bDoNotLoadVehicleGraphics = optini.sections["Graphics"].values["NoVehicleGraphics"] == "1"; - opts.bDoNotLoadBuildingGraphics = optini.sections["Graphics"].values["NoBuildingGraphics"] == "1"; - opts.bDoNotLoadInfantryGraphics = optini.sections["Graphics"].values["NoInfantryGraphics"] == "1"; - opts.bDoNotLoadTreeGraphics = optini.sections["Graphics"].values["NoTreeGraphics"] == "1"; - opts.bDoNotLoadSnowGraphics = optini.sections["Graphics"].values["NoSnowGraphics"] == "1"; - opts.bDoNotLoadTemperateGraphics = optini.sections["Graphics"].values["NoTemperateGraphics"] == "1"; - opts.bDoNotLoadBMPs = optini.sections["Graphics"].values["NoBMPs"] == "1"; - opts.bDoNotLoadOverlayGraphics = optini.sections["Graphics"].values["NoOverlayGraphics"] == "1"; - opts.bVSync = optini.sections["Graphics"].values.emplace("VSync", opts.bVSync ? "1" : "0").first->second == "1"; + auto const& userInterfaceSec = optini["UserInterface"]; + opts.bDisableAutoShore = userInterfaceSec.GetBool("DisableAutoShore"); + opts.bDisableAutoLat = userInterfaceSec.GetBool("DisableAutoLat"); + opts.bNoSounds = !userInterfaceSec.GetBool("Sounds"); + opts.bDisableSlopeCorrection = userInterfaceSec.GetBool("DisableSlopeCorrection"); + opts.fLoadScreenDelayInSeconds = userInterfaceSec.GetFloat("LoadScreenDelay", opts.fLoadScreenDelayInSeconds); + opts.bShowStats = userInterfaceSec.GetBool("ShowStats", opts.bShowStats); + opts.bHighResUI = userInterfaceSec.GetBool("HighRes", opts.bHighResUI); + opts.useDefaultMouseCursor = userInterfaceSec.GetBool("UseDefaultMouseCursor", opts.useDefaultMouseCursor); - opts.bDisableAutoShore = optini.sections["UserInterface"].values["DisableAutoShore"] == "1"; - opts.bDisableAutoLat = optini.sections["UserInterface"].values["DisableAutoLat"] == "1"; - opts.bNoSounds = optini.sections["UserInterface"].values["Sounds"] != "1"; - opts.bDisableSlopeCorrection = optini.sections["UserInterface"].values["DisableSlopeCorrection"] == "1"; - opts.fLoadScreenDelayInSeconds = static_cast(atof(optini.sections["UserInterface"].values.emplace("LoadScreenDelay", std::to_string(opts.fLoadScreenDelayInSeconds).c_str()).first->second)); - opts.bShowStats = optini.sections["UserInterface"].values.emplace("ShowStats", opts.bShowStats ? "1" : "0").first->second == "1"; - opts.bHighResUI = optini.sections["UserInterface"].values.emplace("HighRes", opts.bHighResUI ? "1" : "0").first->second == "1"; - opts.useDefaultMouseCursor = optini.sections["UserInterface"].values.emplace("UseDefaultMouseCursor", opts.useDefaultMouseCursor ? "1" : "0").first->second == "1"; - - opts.fMiniMapScale = static_cast(atof(optini.sections["MiniMap"].values.emplace("Scale", std::to_string(opts.fMiniMapScale).c_str()).first->second)); + opts.fMiniMapScale = optini["MiniMap"].GetFloat("Scale", opts.fMiniMapScale); auto defaultViewSteps = CString(Join(",", opts.viewScaleSteps | std::views::transform([](auto v) {return std::to_string(v); })).c_str()); - auto viewScaleStepsRange = SplitParams(optini.sections["UserInterface"].values.emplace("ViewScaleSteps", defaultViewSteps).first->second) | std::views::transform([](auto v) { return static_cast(std::atof(v)); }); + auto viewScaleStepsRange = SplitParams(userInterfaceSec.GetStringOr("ViewScaleSteps", defaultViewSteps)) | std::views::transform([](auto v) { return static_cast(std::atof(v)); }); opts.viewScaleSteps.assign(viewScaleStepsRange.begin(), viewScaleStepsRange.end()); - opts.viewScaleUseSteps = optini.sections["UserInterface"].values.emplace("ViewScaleUseSteps", opts.viewScaleUseSteps ? "1" : "0").first->second == "1"; - opts.viewScaleSpeed = static_cast(atof(optini.sections["UserInterface"].values.emplace("ViewScaleSpeed", std::to_string(opts.viewScaleSpeed).c_str()).first->second)); + opts.viewScaleUseSteps = userInterfaceSec.GetBool("ViewScaleUseSteps", opts.viewScaleUseSteps); + opts.viewScaleSpeed = userInterfaceSec.GetFloat("ViewScaleSpeed", opts.viewScaleSpeed); // MW 07/19/01 - opts.bShowCells = optini.sections["UserInterface"].values["ShowBuildingCells"] == "1"; + opts.bShowCells = userInterfaceSec.GetBool("ShowBuildingCells"); optini.SaveFile(iniFile); // MW 07/20/01: Load file list int i; - for (i = 0;i < 4;i++) - { + for (i = 0;i < 4;i++) { char c[50]; itoa(i, c, 10); - opts.prev_maps[i] = optini.sections["Files"].values[c]; + opts.prev_maps[i] = optini.GetString("Files", c); } - if (opts.bDoNotLoadTemperateGraphics && opts.bDoNotLoadSnowGraphics) - { + if (opts.bDoNotLoadTemperateGraphics && opts.bDoNotLoadSnowGraphics) { MessageBox(0, "You have turned off loading of both snow and temperate terrain in 'FinalAlert.ini'. At least one of these must be loaded. The application will now quit.", "Error", 0); exit(-982); } int EasyView; - if (optini.sections["UserInterface"].FindName("EasyView") < 0) - { + if (userInterfaceSec.FindIndex("EasyView") < 0) { MessageBox(0, GetLanguageStringACP("ExplainEasyView"), GetLanguageStringACP("ExplainEasyViewCap"), 0); EasyView = 1; optini.LoadFile(iniFile); - optini.sections["UserInterface"].values["EasyView"] = "1"; + optini.SetInteger("UserInterface", "EasyView", 1); optini.SaveFile(iniFile); + } else { + EasyView = userInterfaceSec.GetInteger("EasyView"); } - else - { - EasyView = atoi(optini.sections["UserInterface"].values["EasyView"]); + if (EasyView != 0) { + theApp.m_Options.bEasy = TRUE; } - if (EasyView != 0) theApp.m_Options.bEasy = TRUE; diff --git a/MissionEditor/FinalSunDlg.cpp b/MissionEditor/FinalSunDlg.cpp index 5c3c4b2..076c2ca 100644 --- a/MissionEditor/FinalSunDlg.cpp +++ b/MissionEditor/FinalSunDlg.cpp @@ -536,7 +536,7 @@ void CFinalSunDlg::OnFileOpenmap() FSunPackLib::XCC_ExtractFile(pktFile, extractFile, hMix); m_PKTHeader.LoadFile(extractFile, TRUE); - fileToOpen=m_PKTHeader.sections["MultiMaps"].values["1"]+".map"; + fileToOpen = m_PKTHeader.GetString("MultiMaps", "1") + ".map"; @@ -553,8 +553,8 @@ void CFinalSunDlg::OnFileOpenmap() CIniFile f; f.InsertFile(fileToOpen, "Map"); - if((f.sections["Map"].values["Theater"]==THEATER0 && theApp.m_Options.bDoNotLoadTemperateGraphics) || (f.sections["Map"].values["Theater"]==THEATER1 && theApp.m_Options.bDoNotLoadSnowGraphics)) - { + auto const& theaterType = f.GetString("Map", "Theater"); + if ((theaterType == THEATER0 && theApp.m_Options.bDoNotLoadTemperateGraphics) || (theaterType == THEATER1 && theApp.m_Options.bDoNotLoadSnowGraphics)) { MessageBox("You have selected to don´t show temperate or snow theater, but this map uses this theater. You cannot load it without restarting FinalSun/FinalAlert 2 with this theater enabled.", "Error"); return; } @@ -648,32 +648,61 @@ void CFinalSunDlg::UpdateDialogs(BOOL bOnlyMissionControl, BOOL bNoRepos) OutputDebugString("Dialogs updated\n"); - if(m_basic.m_hWnd) m_basic.UpdateDialog(); - if(m_all.m_hWnd) m_all.UpdateDialog(); - if(m_map.m_hWnd) m_map.UpdateDialog(); - if(m_lighting.m_hWnd) m_lighting.UpdateDialog(); - if(m_specialflags.m_hWnd) m_specialflags.UpdateDialog(); - if(m_teamtypes.m_hWnd) m_teamtypes.UpdateDialog(); - if(m_houses.m_hWnd) m_houses.UpdateDialog(); - if(m_taskforces.m_hWnd) m_taskforces.UpdateDialog(); - if(m_Scripttypes.m_hWnd) m_Scripttypes.UpdateDialog(); - if(m_triggers.m_hWnd) m_triggers.UpdateDialog(); - if(m_triggereditor.m_hWnd) m_triggereditor.UpdateDialog(); - if(m_tags.m_hWnd) m_tags.UpdateDialog(); - if(m_aitriggertypesenable.m_hWnd) m_aitriggertypesenable.UpdateDialog(); - if(m_aitriggertypes.m_hWnd) m_aitriggertypes.UpdateDialog(); - if(m_singleplayersettings.m_hWnd) m_singleplayersettings.UpdateDialog(); + if (m_basic.m_hWnd) { + m_basic.UpdateDialog(); + } + if (m_all.m_hWnd) { + m_all.UpdateDialog(); + } + if (m_map.m_hWnd) { + m_map.UpdateDialog(); + } + if (m_lighting.m_hWnd) { + m_lighting.UpdateDialog(); + } + if (m_specialflags.m_hWnd) { + m_specialflags.UpdateDialog(); + } + if (m_teamtypes.m_hWnd) { + m_teamtypes.UpdateDialog(); + } + if (m_houses.m_hWnd) { + m_houses.UpdateDialog(); + } + if (m_taskforces.m_hWnd) { + m_taskforces.UpdateDialog(); + } + if (m_Scripttypes.m_hWnd) { + m_Scripttypes.UpdateDialog(); + } + if (m_triggers.m_hWnd) { + m_triggers.UpdateDialog(); + } + if (m_triggereditor.m_hWnd) { + m_triggereditor.UpdateDialog(); + } + if (m_tags.m_hWnd) { + m_tags.UpdateDialog(); + } + if (m_aitriggertypesenable.m_hWnd) { + m_aitriggertypesenable.UpdateDialog(); + } + if (m_aitriggertypes.m_hWnd) { + m_aitriggertypes.UpdateDialog(); + } + if (m_singleplayersettings.m_hWnd) { + m_singleplayersettings.UpdateDialog(); + } CIniFile& ini=Map->GetIniFile(); - if(ini.sections.find(MAPHOUSES)!=ini.sections.end() && ini.sections[MAPHOUSES].values.size()>0) - { - if(ini.sections[MAPHOUSES].FindValue("Neutral")>=0) - currentOwner="Neutral"; - else - currentOwner=*ini.sections[MAPHOUSES].GetValue(0); + + currentOwner = "Neutral"; + auto const& houseSec = ini[MAPHOUSES]; + if (houseSec.Size() > 0) { + if (!houseSec.HasValue("Neutral")) { + currentOwner = ini[MAPHOUSES].Nth(0).second; + } } - else - currentOwner="Neutral";//*rules.sections[HOUSES].GetValue(0); if(!bOnlyMissionControl) { @@ -686,8 +715,9 @@ void CFinalSunDlg::UpdateDialogs(BOOL bOnlyMissionControl, BOOL bNoRepos) m_view.m_objectview->UpdateDialog(); m_view.m_minimap.UpdateView(); - if(tiles!=NULL && tiledata!=NULL && tiledata_count!=NULL) - m_view.m_browser->m_bar.Update(); + if (tiles != NULL && tiledata != NULL && tiledata_count != NULL) { + m_view.m_browser->m_bar.Update(); + } } AD.reset(); @@ -904,41 +934,36 @@ void CFinalSunDlg::SaveMap(CString FileName_) } char c[50]; CIniFile& ini=Map->GetIniFile(); - CIniFileSection& sec=ini.sections["Header"]; - itoa(wp_count, c, 10); - sec.values["NumberStartingPoints"]=c; - for(i=0;i<8;i++) - { - CString s="Waypoint"; - itoa(i+1, c, 10); - s+=c; + auto const sec = ini.TryGetSection("Header"); + sec->SetInteger("NumberStartingPoints", wp_count); + for (i = 0; i < 8; i++) { + CString key = "Waypoint"; + itoa(i + 1, c, 10); + key += c; itoa(xw[i], c, 10); - CString val=c; - val+=","; + CString val = c; + val += ","; itoa(yw[i], c, 10); - val+=c; - sec.values[s]=val; + val += c; + sec->SetString(key, val); } int startx, starty, width, height; MC_GetHeaderRect(startx, starty, width, height); - itoa(height, c, 10); - sec.values["Height"]=c; - itoa(width, c, 10); - sec.values["Width"]=c; + sec->SetInteger("Height", height); + sec->SetInteger("Width", width); //CIniFile& ini=Map->GetIniFile(); - - CString left=GetParam(ini.sections["Map"].values["LocalSize"], 0); - CString top=GetParam(ini.sections["Map"].values["LocalSize"], 1); + auto const& localSizeStr = ini.GetString("Map", "LocalSize"); + CString left = GetParam(localSizeStr, 0); + CString top = GetParam(localSizeStr, 1); //startx=1;//Map->GetHeight()/2;//atoi(left);//Map->GetIsoSize()/2-Map->GetWidth()/2;//198/2-50;//Map->GetIsoSize()/2-Map->GetHeight()/2;//Map->GetWidth()/2-50; //starty=Map->GetWidth();//Map->GetIsoSize()/2-Map->GetWidth()/2;//198/2-50;//Map->GetIsoSize()/2-Map->GetWidth()/2;//Map->GetHeight()/2-50; itoa(startx, c, 10); - sec.values["StartX"]=c; - itoa(starty, c, 10); - sec.values["StartY"]=c; + sec->SetInteger("StartX", startx); + sec->SetInteger("StartY", starty); /*CMultiSaveOptionsDlg mso; @@ -982,51 +1007,72 @@ void CFinalSunDlg::SaveMap(CString FileName_) CString MAPFileName=CoreName; MAPFileName+=".map"; - DWORD dwFlags=MAPDATA_UPDATE_TO_INI_ALL; + DWORD dwFlags = MAPDATA_UPDATE_TO_INI_ALL; - if(!bSaveAsMMX) - { + if (!bSaveAsMMX) { CSaveMapOptionsDlg opt; - CString gm=Map->GetIniFile().sections["Basic"].values["GameMode"]; + CString gm = Map->GetIniFile().GetString("Basic", "GameMode"); gm.MakeLower(); - if(gm.GetLength()) - { - opt.m_Standard=gm.Find("standard")>=0; - opt.m_AirWar=gm.Find("airwar")>=0; - opt.m_Cooperative=gm.Find("cooperative")>=0; - opt.m_Duel=gm.Find("duel")>=0; - opt.m_Navalwar=gm.Find("navalwar")>=0; - opt.m_Nukewar=gm.Find("nukewar")>=0; - opt.m_Meatgrind=gm.Find("meatgrind")>=0; - opt.m_Megawealth=gm.Find("megawealth")>=0; - opt.m_TeamGame=gm.Find("teamgame")>=0; + if (gm.GetLength()) { + opt.m_Standard = gm.Find("standard") >= 0; + opt.m_AirWar = gm.Find("airwar") >= 0; + opt.m_Cooperative = gm.Find("cooperative") >= 0; + opt.m_Duel = gm.Find("duel") >= 0; + opt.m_Navalwar = gm.Find("navalwar") >= 0; + opt.m_Nukewar = gm.Find("nukewar") >= 0; + opt.m_Meatgrind = gm.Find("meatgrind") >= 0; + opt.m_Megawealth = gm.Find("megawealth") >= 0; + opt.m_TeamGame = gm.Find("teamgame") >= 0; + } else { + opt.m_Standard = TRUE; } - else - opt.m_Standard=TRUE; - - if(opt.DoModal()==IDCANCEL) return; + if (opt.DoModal() == IDCANCEL) { + return; + } - gm=""; - if(opt.m_Standard) gm+="standard, "; - if(opt.m_Meatgrind) gm+="meatgrind, "; - if(opt.m_Navalwar) gm+="navalwar, "; - if(opt.m_Nukewar) gm+="nukewar, "; - if(opt.m_AirWar) gm+="airwar, "; - if(opt.m_Megawealth) gm+="megawealth, "; - if(opt.m_Duel) gm+="duel, "; - if(opt.m_Cooperative) gm+="cooperative, "; - if(opt.m_TeamGame) gm+="teamgame, "; + gm = ""; + if (opt.m_Standard) { + gm += "standard, "; + } + if (opt.m_Meatgrind) { + gm += "meatgrind, "; + } + if (opt.m_Navalwar) { + gm += "navalwar, "; + } + if (opt.m_Nukewar) { + gm += "nukewar, "; + } + if (opt.m_AirWar) { + gm += "airwar, "; + } + if (opt.m_Megawealth) { + gm += "megawealth, "; + } + if (opt.m_Duel) { + gm += "duel, "; + } + if (opt.m_Cooperative) { + gm += "cooperative, "; + } + if (opt.m_TeamGame) { + gm += "teamgame, "; + } - if(gm.ReverseFind(',')>=0) gm=gm.Left(gm.ReverseFind(',')); + if (gm.ReverseFind(',') >= 0) { + gm = gm.Left(gm.ReverseFind(',')); + } - if(gm.GetLength()==0) gm="standard"; + if (gm.GetLength() == 0) { + gm = "standard"; + } - Map->GetIniFile().sections["Basic"].values["Name"]=opt.m_MapName; - Map->GetIniFile().sections["Basic"].values["GameMode"]=gm; + Map->GetIniFile().SetString("Basic", "Name", opt.m_MapName); + Map->GetIniFile().SetString("Basic", "GameMode", gm); int i; int count=0; @@ -1037,44 +1083,56 @@ void CFinalSunDlg::SaveMap(CString FileName_) Map->GetWaypointData(i, &id, &pos); int idi; idi=atoi(id); - if(idi!=i) break; - if(idi>=0 && idi<8) count++; + if (idi != i) { + break; + } + if (idi >= 0 && idi < 8) { + count++; + } } - if(count<2) count=2; - - Map->GetIniFile().sections["Basic"].values["MinPlayer"]="2"; - char c[50]; - itoa(count, c, 10); - Map->GetIniFile().sections["Basic"].values["MaxPlayer"]=c; + if (count < 2) { + count = 2; + } + // TODO: control from dialog + Map->GetIniFile().SetInteger("Basic", "MinPlayer", 2); + Map->GetIniFile().SetInteger("Basic", "MaxPlayer", count); - if(opt.m_Compress==0) dwFlags|=MAPDATA_UPDATE_TO_INI_ALL_COMPRESSED; - if(opt.m_PreviewMode==0) dwFlags|=MAPDATA_UPDATE_TO_INI_ALL_PREVIEW; - if(opt.m_PreviewMode==2) hidePreview=TRUE; - } - else - { + if (opt.m_Compress == 0) { + dwFlags |= MAPDATA_UPDATE_TO_INI_ALL_COMPRESSED; + } + if (opt.m_PreviewMode == 0) { + dwFlags |= MAPDATA_UPDATE_TO_INI_ALL_PREVIEW; + } + if (opt.m_PreviewMode == 2) { + hidePreview = TRUE; + } + } else { CMMXSavingOptionsDlg opt; - - if(m_PKTHeader.sections.size()>0) // old pkt header exists - { - CIniFileSection& sec=m_PKTHeader.sections[m_PKTHeader.sections["MultiMaps"].values["1"]]; - if(sec.values["Description"].GetLength()>0) opt.m_Description=sec.values["Description"]; - opt.m_MinPlayers=atoi(sec.values["MinPlayers"])-2; - opt.m_Maxplayers=atoi(sec.values["MaxPlayers"])-2; - CString gm=sec.values["GameMode"]; + // old pkt header exists + if (m_PKTHeader.Size() > 0) { + auto const& sec = m_PKTHeader[m_PKTHeader.GetString("MultiMaps", "1")]; + auto const& desc = sec.GetString("Description"); + if (!desc.IsEmpty()) { + opt.m_Description = desc; + } + opt.m_MinPlayers = sec.GetInteger("MinPlayers") - 2; + opt.m_Maxplayers = sec.GetInteger("MaxPlayers") - 2; + CString gm = sec["GameMode"]; gm.MakeLower(); - opt.m_Standard=gm.Find("standard")>=0; - opt.m_AirWar=gm.Find("airwar")>=0; - opt.m_Cooperative=gm.Find("cooperative")>=0; - opt.m_Duel=gm.Find("duel")>=0; - opt.m_NavalWar=gm.Find("navalwar")>=0; - opt.m_NukeWar=gm.Find("nukewar")>=0; - opt.m_Meatgrind=gm.Find("meatgrind")>=0; - opt.m_MegaWealth=gm.Find("megawealth")>=0; + opt.m_Standard = gm.Find("standard") >= 0; + opt.m_AirWar = gm.Find("airwar") >= 0; + opt.m_Cooperative = gm.Find("cooperative") >= 0; + opt.m_Duel = gm.Find("duel") >= 0; + opt.m_NavalWar = gm.Find("navalwar") >= 0; + opt.m_NukeWar = gm.Find("nukewar") >= 0; + opt.m_Meatgrind = gm.Find("meatgrind") >= 0; + opt.m_MegaWealth = gm.Find("megawealth") >= 0; } - if(opt.DoModal()==IDCANCEL) return; + if (opt.DoModal() == IDCANCEL) { + return; + } Description=opt.m_Description; standard=opt.m_Standard; @@ -1091,7 +1149,7 @@ void CFinalSunDlg::SaveMap(CString FileName_) dwFlags|=MAPDATA_UPDATE_TO_INI_ALL_PREVIEW; - Map->GetIniFile().sections["Basic"].values["Official"]="Yes"; + Map->GetIniFile().SetBool("Basic", "Official", "Yes"); // Map->GetIniFile().sections["Basic"].values["Name"]=opt.m_Description; } @@ -1112,22 +1170,21 @@ void CFinalSunDlg::SaveMap(CString FileName_) CIniFile& ini=Map->GetIniFile(); - - int i; - - for(i=0;ivalues.size()==0 || ini.GetSectionName(i)->GetLength()==0) - { - ini.sections.erase(*ini.GetSectionName(i)); + // delete invalid ini sections + for (auto it = ini.begin(); it != ini.end();) { + if (it->second.Size() == 0 || it->first.IsEmpty()) { + it = ini.DeleteAt(it); } + ++it; } - for(i=0;iTrimLeft(); @@ -1160,7 +1217,7 @@ void CFinalSunDlg::SaveMap(CString FileName_) } } } - +#endif SetText("Saving..."); @@ -1206,196 +1263,183 @@ void CFinalSunDlg::SaveMap(CString FileName_) fi=""; // MW 07/28/01: Header saving at top - for(i=0;iIsRulesSection(*ini.GetSectionName(i))) - { - rulessections[*ini.GetSectionName(i)]=TRUE; + for (auto const& [secName, sec] : ini) { + if (!Map->IsRulesSection(secName)) { + continue; + } + rulessections[secName] = TRUE; - fi= "[" ; - fi+= *ini.GetSectionName(i); - fi+= "]" ; - fi+= "\n"; + fi = "["; + fi += secName; + fi += "]"; + fi += "\n"; + WriteFile(hFile, fi, fi.GetLength(), &bwr, NULL); + + char c[50]; + for (auto e = 0; e < sec.Size(); e++) { + auto const& [key, value] = sec.Nth(e); + fi = key; + fi += "="; + fi += value; + fi += "\n"; WriteFile(hFile, fi, fi.GetLength(), &bwr, NULL); - - int e; - CIniFileSection& sec=*ini.GetSection(i); - CString d; - - - char c[50]; - for(e=0;edata()); - - + + for (auto const pSec : handledSections) { + if (pSec == secName) { + return true; + } + } + + return false; + }; + + for (auto const& [secName, sec] : ini) { + if (alreadyHandledSections(secName)) { + continue; + } + if (!secName.IsEmpty()) { + //MessageBox(secName); //its a standard section: - fi= "[" ; - fi+= *ini.GetSectionName(i); - fi+= "]" ; - fi+= "\n"; + fi = "["; + fi += secName; + fi += "]"; + fi += "\n"; WriteFile(hFile, fi, fi.GetLength(), &bwr, NULL); - - int e; - CIniFileSection& sec=*ini.GetSection(i); - CString d; - - + char c[50]; - for(e=0;e=0) gm=gm.Left(gm.ReverseFind(',')); + if (gm.ReverseFind(',') >= 0) { + gm = gm.Left(gm.ReverseFind(',')); + } - f.sections[CoreName].values["GameMode"]=gm; + f.SetString(CoreName, "GameMode", gm); char c[50]; - itoa(maxplayers, c, 10); - f.sections[CoreName].values["MaxPlayers"]=c; - itoa(minplayers,c,10); - f.sections[CoreName].values["MinPlayers"]=c; + f.SetInteger( CoreName,"MaxPlayers", maxplayers); + f.SetInteger(CoreName, "MinPlayers", minplayers); - f.sections[CoreName].values["CD"]="0,1"; + f.SetString(CoreName, "CD", "0,1"); f.SaveFile(PKTFileName); LPCSTR files[2]; - files[0]=(LPCSTR)PKTFileName; - files[1]=(LPCSTR)MAPFileName; + files[0] = (LPCSTR)PKTFileName; + files[1] = (LPCSTR)MAPFileName; #ifdef RA2_MODE auto game = yuri_mode ? FSunPackLib::Game::RA2_YR : FSunPackLib::Game::RA2; @@ -1613,11 +1673,10 @@ void CFinalSunDlg::OnDebugExportmappacknosections() int i; - ovrl=""; + ovrl = ""; - for(i=0;iGetIniFile(); - - int i; - for(i=0;iGetIniFile(), SectionType); } void CFinalSunDlg::OnFileNew() @@ -1700,13 +1760,14 @@ void CFinalSunDlg::OnFileNew() CString plhouse; BOOL bPrepareHouses=FALSE; BOOL bAutoProd=FALSE; - if(bSingleplayer) - { + if (bSingleplayer) { CNewMapSpDlg spdlg; - if(spdlg.DoModal()==IDCANCEL) return; + if (spdlg.DoModal() == IDCANCEL) { + return; + } bPrepareHouses=spdlg.m_PrepareHouses; bAutoProd=spdlg.m_AutoProd; - plhouse=*rules.sections[HOUSES].GetValue(spdlg.m_House); + plhouse = rules[HOUSES].Nth(spdlg.m_House).second; } bNoDraw=TRUE; @@ -1750,7 +1811,7 @@ void CFinalSunDlg::OnFileNew() Map->ClearOverlayData(); } - CIniFile& ini=Map->GetIniFile(); + CIniFile& ini = Map->GetIniFile(); int i; int count=Map->GetTerrainCount(); @@ -1776,31 +1837,20 @@ void CFinalSunDlg::OnFileNew() Map->DeleteAircraft(0); } - ini.sections["Basic"].values["Name"]="Noname"; + ini.SetString("Basic", "Name", "Noname"); - for(i=0;iGetIniFile(); - if(!bSingleplayer) ini.sections["Basic"].values["MultiplayerOnly"]="1"; + if (!bSingleplayer) { + ini.SetString("Basic", "MultiplayerOnly", "1"); + } - if(bSingleplayer) - { - ini.sections["Basic"].values["MultiplayerOnly"]="0"; + if (bSingleplayer) { + ini.SetString("Basic", "MultiplayerOnly", "0"); - ini.sections.erase("Preview"); - ini.sections.erase("PreviewPack"); - + ini.DeleteSection("Preview"); + ini.DeleteSection("PreviewPack"); - - - if(bPrepareHouses) - { + if (bPrepareHouses) { //CString plhouse; //plhouse=GetHouseSectionName(dlg.m_House); - plhouse+=" House"; - ini.sections["Basic"].values["Player"]=plhouse; - - int i; - for (i=0;iLoadMenu(IDR_MAIN); - int i,e; - for(i=0;iGetMenuItemCount();i++) + int idx,e; + for(idx=0;idxGetMenuItemCount();idx++) { MENUITEMINFO mii; ZeroMemory(&mii, sizeof(MENUITEMINFO)); mii.cbSize=sizeof(MENUITEMINFO); mii.fMask=MIIM_ID | MIIM_STATE | MIIM_TYPE; - my_menu->GetMenuItemInfo(i, &mii, TRUE); - my_menu->GetMenuString(i, str, MF_BYPOSITION); - my_menu->ModifyMenu(i,mii.fState | mii.fType | MF_BYPOSITION | MF_STRING, mii.wID, TranslateStringACP((LPCTSTR)str)); - for(e=0;eGetSubMenu(i)->GetMenuItemCount();e++) + my_menu->GetMenuItemInfo(idx, &mii, TRUE); + my_menu->GetMenuString(idx, str, MF_BYPOSITION); + my_menu->ModifyMenu(idx,mii.fState | mii.fType | MF_BYPOSITION | MF_STRING, mii.wID, TranslateStringACP((LPCTSTR)str)); + for(e=0;eGetSubMenu(idx)->GetMenuItemCount();e++) { - int id=my_menu->GetSubMenu(i)->GetMenuItemID(e); + int id=my_menu->GetSubMenu(idx)->GetMenuItemID(e); ZeroMemory(&mii, sizeof(MENUITEMINFO)); mii.cbSize=sizeof(MENUITEMINFO); mii.fMask=MIIM_ID | MIIM_STATE | MIIM_TYPE; - my_menu->GetSubMenu(i)->GetMenuItemInfo(e, &mii, TRUE); - my_menu->GetSubMenu(i)->GetMenuString(e, str, MF_BYPOSITION); - my_menu->GetSubMenu(i)->ModifyMenu(e,mii.fState | mii.fType | MF_BYPOSITION | MF_STRING, mii.wID, TranslateStringACP((LPCTSTR)str)); + my_menu->GetSubMenu(idx)->GetMenuItemInfo(e, &mii, TRUE); + my_menu->GetSubMenu(idx)->GetMenuString(e, str, MF_BYPOSITION); + my_menu->GetSubMenu(idx)->ModifyMenu(e,mii.fState | mii.fType | MF_BYPOSITION | MF_STRING, mii.wID, TranslateStringACP((LPCTSTR)str)); } } @@ -2092,20 +2130,20 @@ void CFinalSunDlg::UpdateStrings() // MW 07/20/01: Show prev. opened files int prev_maps_count=0; - for(i=0;i<4;i++) + for(idx=0;idx<4;idx++) { - if(theApp.m_Options.prev_maps[i].GetLength()>0) + if(theApp.m_Options.prev_maps[idx].GetLength()>0) { prev_maps_count++; int id=0; CString str="bla"; - str=theApp.m_Options.prev_maps[i]; + str=theApp.m_Options.prev_maps[idx]; - if(i==0) id=ID_FILE_FILE1; - else if(i==1) id=ID_FILE_FILE2; - else if(i==2) id=ID_FILE_FILE3; - else if(i==3) id=ID_FILE_FILE4; + if(idx==0) id=ID_FILE_FILE1; + else if(idx==1) id=ID_FILE_FILE2; + else if(idx==2) id=ID_FILE_FILE3; + else if(idx==3) id=ID_FILE_FILE4; my_menu->GetSubMenu(0)->InsertMenu(10+prev_maps_count, MF_BYPOSITION | MF_STRING, id, str); } @@ -2121,14 +2159,14 @@ void CFinalSunDlg::UpdateStrings() if(theApp.m_Options.bEasy) { CMenu* edit_my_menu=my_menu->GetSubMenu(1); - for(i=edit_my_menu->GetMenuItemCount()-1;i>=11;i--) // MW 07/17/2001: i>=9 changed to i>=10 so Basic dialog is always available + for(idx=edit_my_menu->GetMenuItemCount()-1;idx>=11;idx--) // MW 07/17/2001: i>=9 changed to i>=10 so Basic dialog is always available { - edit_my_menu->DeleteMenu(i, MF_BYPOSITION); + edit_my_menu->DeleteMenu(idx, MF_BYPOSITION); } CMenu* terrain_my_menu=my_menu->GetSubMenu(2); - for(i=terrain_my_menu->GetMenuItemCount()-1;i>=8;i--) + for(idx=terrain_my_menu->GetMenuItemCount()-1;idx>=8;idx--) { - terrain_my_menu->DeleteMenu(i, MF_BYPOSITION); + terrain_my_menu->DeleteMenu(idx, MF_BYPOSITION); } } @@ -2247,20 +2285,17 @@ void CFinalSunDlg::OnOptionsSimpleview() Options.LoadFile(u8AppDataPath+"\\FinalAlert.ini"); #endif - if(GetMenu()->GetMenuState(ID_OPTIONS_SIMPLEVIEW, MF_BYCOMMAND) & MF_CHECKED) - { + if (GetMenu()->GetMenuState(ID_OPTIONS_SIMPLEVIEW, MF_BYCOMMAND) & MF_CHECKED) { GetMenu()->CheckMenuItem(ID_OPTIONS_SIMPLEVIEW, MF_BYCOMMAND | MF_UNCHECKED); theApp.m_Options.bEasy=FALSE; - Options.sections["UserInterface"].values["EasyView"]="0"; + Options.SetInteger("UserInterface", "EasyView", 0); // hide all dialogs: HideAllDialogs(); - } - else - { + } else { GetMenu()->CheckMenuItem(ID_OPTIONS_SIMPLEVIEW, MF_BYCOMMAND | MF_CHECKED); theApp.m_Options.bEasy=TRUE; - Options.sections["UserInterface"].values["EasyView"]="1"; + Options.SetInteger("UserInterface", "EasyView", 1); } UpdateStrings(); @@ -2670,7 +2705,7 @@ BOOL CFinalSunDlg::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult) if(pHead->code==TTN_NEEDTEXT) { TOOLTIPTEXT *pTTT = (TOOLTIPTEXT *)pHead; - UINT nID =pHead->idFrom; + auto nID =pHead->idFrom; if (pTTT->uFlags & TTF_IDISHWND) { // idFrom ist der HWND des Tools @@ -2851,10 +2886,10 @@ void CFinalSunDlg::OnTerrainShowallfields() return; } - int i; - for(i=0;iGetIsoSize()*Map->GetIsoSize();i++) + int idx; + for(idx=0;idxGetIsoSize()*Map->GetIsoSize();idx++) { - Map->HideField(i, FALSE); + Map->HideField(idx, FALSE); } m_view.m_isoview->RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW); @@ -2917,11 +2952,11 @@ void CFinalSunDlg::OnMaptoolsChangemapheight() int mapwidth=Map->GetWidth(); int mapheight=Map->GetHeight(); int max=Map->GetIsoSize()*Map->GetIsoSize(); - int i; - for(i=0;imapwidth+mapheight*2 || (dwY+1>mapwidth && dwXmapwidth && dwY+mapwidthmapwidth+mapheight*2 || (dwY+2>mapwidth && dwX-2mapwidth && dwY+mapwidth-2GetHeightAt(i); + int v=Map->GetHeightAt(idx); if(v+vmin <0) { vmin=-v; @@ -2962,10 +2997,10 @@ void CFinalSunDlg::OnMaptoolsChangemapheight() - for(i=0;imapwidth+mapheight*2 || (dwY+1>mapwidth && dwXmapwidth && dwY+mapwidthmapwidth+mapheight*2 || (dwY+2>mapwidth && dwX-2mapwidth && dwY+mapwidth-2GetHeightAt(i); + int v=Map->GetHeightAt(idx); if(v+a <0 || v+a>MAXHEIGHT) { MessageBox(GetLanguageStringACP("StrChangeHeightErr"), GetLanguageStringACP("StrChangeHeightErrCap"), MB_ICONSTOP); @@ -2984,10 +3019,10 @@ void CFinalSunDlg::OnMaptoolsChangemapheight() } } - for(i=0;iGetHeightAt(i); - Map->SetHeightAt(i, v+a); + int v=Map->GetHeightAt(idx); + Map->SetHeightAt(idx, v+a); } this->m_view.m_isoview->RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW); @@ -3055,7 +3090,7 @@ LONG __stdcall ExceptionHandler( CString s_add; char adress[50]; char c[50]; - itoa((int)ExceptionInfo->ExceptionRecord->ExceptionAddress, adress, 16); + itoa((std::ptrdiff_t)ExceptionInfo->ExceptionRecord->ExceptionAddress, adress, 16); s="Unknown exception"; switch(ExceptionInfo->ExceptionRecord->ExceptionCode) { @@ -3217,7 +3252,7 @@ LONG __stdcall ExceptionHandler( return EXCEPTION_EXECUTE_HANDLER;//EXCEPTION_CONTINUE_SEARCH;//EXCEPTION_EXECUTE_HANDLER; } -int CFinalSunDlg::DoModal() +INT_PTR CFinalSunDlg::DoModal() { int res=0; SetUnhandledExceptionFilter(ExceptionHandler); @@ -3513,17 +3548,14 @@ void CFinalSunDlg::OnOptionsDisableautoshore() Options.LoadFile(u8AppDataPath+"\\FinalAlert.ini"); #endif - if(GetMenu()->GetMenuState(ID_OPTIONS_DISABLEAUTOSHORE, MF_BYCOMMAND) & MF_CHECKED) - { + if (GetMenu()->GetMenuState(ID_OPTIONS_DISABLEAUTOSHORE, MF_BYCOMMAND) & MF_CHECKED) { GetMenu()->CheckMenuItem(ID_OPTIONS_DISABLEAUTOSHORE, MF_BYCOMMAND | MF_UNCHECKED); theApp.m_Options.bDisableAutoShore=FALSE; - Options.sections["UserInterface"].values["DisableAutoShore"]="0"; - } - else - { + Options.SetBool("UserInterface", "DisableAutoShore", false); + } else { GetMenu()->CheckMenuItem(ID_OPTIONS_DISABLEAUTOSHORE, MF_BYCOMMAND | MF_CHECKED); theApp.m_Options.bDisableAutoShore=TRUE; - Options.sections["UserInterface"].values["DisableAutoShore"]="1"; + Options.SetBool("UserInterface", "DisableAutoShore", true); } @@ -3602,17 +3634,14 @@ void CFinalSunDlg::OnOptionsDisableautolat() Options.LoadFile(u8AppDataPath+"\\FinalAlert.ini"); #endif - if(GetMenu()->GetMenuState(ID_OPTIONS_DISABLEAUTOLAT, MF_BYCOMMAND) & MF_CHECKED) - { + if (GetMenu()->GetMenuState(ID_OPTIONS_DISABLEAUTOLAT, MF_BYCOMMAND) & MF_CHECKED) { GetMenu()->CheckMenuItem(ID_OPTIONS_DISABLEAUTOLAT, MF_BYCOMMAND | MF_UNCHECKED); theApp.m_Options.bDisableAutoLat=FALSE; - Options.sections["UserInterface"].values["DisableAutoLat"]="0"; - } - else - { + Options.SetBool("UserInterface", "DisableAutoLat", false); + } else { GetMenu()->CheckMenuItem(ID_OPTIONS_DISABLEAUTOLAT, MF_BYCOMMAND | MF_CHECKED); theApp.m_Options.bDisableAutoLat=TRUE; - Options.sections["UserInterface"].values["DisableAutoLat"]="1"; + Options.SetBool("UserInterface", "DisableAutoLat", true); } @@ -3696,17 +3725,15 @@ void CFinalSunDlg::OnOptionsSounds() Options.LoadFile(u8AppDataPath+"\\FinalAlert.ini"); #endif - if(GetMenu()->GetMenuState(ID_OPTIONS_SOUNDS, MF_BYCOMMAND) & MF_CHECKED) - { + if (GetMenu()->GetMenuState(ID_OPTIONS_SOUNDS, MF_BYCOMMAND) & MF_CHECKED) { GetMenu()->CheckMenuItem(ID_OPTIONS_SOUNDS, MF_BYCOMMAND | MF_UNCHECKED); theApp.m_Options.bNoSounds=TRUE; - Options.sections["UserInterface"].values["Sounds"]="0"; + Options.SetBool("UserInterface", "Sounds", false); } - else - { + else { GetMenu()->CheckMenuItem(ID_OPTIONS_SOUNDS, MF_BYCOMMAND | MF_CHECKED); theApp.m_Options.bNoSounds=FALSE; - Options.sections["UserInterface"].values["Sounds"]="1"; + Options.SetBool("UserInterface", "Sounds", true); } @@ -3730,17 +3757,14 @@ void CFinalSunDlg::OnOptionsDisableslopecorrection() Options.LoadFile(u8AppDataPath +"\\FinalAlert.ini"); #endif - if(GetMenu()->GetMenuState(ID_OPTIONS_DISABLESLOPECORRECTION, MF_BYCOMMAND) & MF_CHECKED) - { + if (GetMenu()->GetMenuState(ID_OPTIONS_DISABLESLOPECORRECTION, MF_BYCOMMAND) & MF_CHECKED) { GetMenu()->CheckMenuItem(ID_OPTIONS_DISABLESLOPECORRECTION, MF_BYCOMMAND | MF_UNCHECKED); - theApp.m_Options.bDisableSlopeCorrection=FALSE; - Options.sections["UserInterface"].values["DisableSlopeCorrection"]="0"; - } - else - { + theApp.m_Options.bDisableSlopeCorrection=FALSE; + Options.SetBool("UserInterface", "DisableSlopeCorrection", false); + } else { GetMenu()->CheckMenuItem(ID_OPTIONS_DISABLESLOPECORRECTION, MF_BYCOMMAND | MF_CHECKED); theApp.m_Options.bDisableSlopeCorrection=TRUE; - Options.sections["UserInterface"].values["DisableSlopeCorrection"]="1"; + Options.SetBool("UserInterface", "DisableSlopeCorrection", true); } #ifndef RA2_MODE @@ -3760,17 +3784,14 @@ void CFinalSunDlg::OnOptionsShowbuildingoutline() Options.LoadFile(u8AppDataPath+"\\FinalAlert.ini"); #endif - if(GetMenu()->GetMenuState(ID_OPTIONS_SHOWBUILDINGOUTLINE, MF_BYCOMMAND) & MF_CHECKED) - { + if (GetMenu()->GetMenuState(ID_OPTIONS_SHOWBUILDINGOUTLINE, MF_BYCOMMAND) & MF_CHECKED) { GetMenu()->CheckMenuItem(ID_OPTIONS_SHOWBUILDINGOUTLINE, MF_BYCOMMAND | MF_UNCHECKED); theApp.m_Options.bShowCells=FALSE; - Options.sections["UserInterface"].values["ShowBuildingCells"]="0"; - } - else - { + Options.SetBool("UserInterface", "ShowBuildingCells", false); + } else { GetMenu()->CheckMenuItem(ID_OPTIONS_SHOWBUILDINGOUTLINE, MF_BYCOMMAND | MF_CHECKED); theApp.m_Options.bShowCells=TRUE; - Options.sections["UserInterface"].values["ShowBuildingCells"]="1"; + Options.SetBool("UserInterface", "ShowBuildingCells", true); } m_view.m_isoview->RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW); @@ -3810,12 +3831,12 @@ void CFinalSunDlg::OnFileFile4() // MW 07/20/01: Checks if file already exists in prev. files list. If not, adds it (may delete old ones) void CFinalSunDlg::InsertPrevFile(CString lpFilename) { - int i; + int idx; //int free_at=-1; - for(i=0;i<4;i++) + for(idx=0;idx<4;idx++) { - CString f=theApp.m_Options.prev_maps[i]; + CString f=theApp.m_Options.prev_maps[idx]; CString f2=lpFilename; f2.MakeLower(); f.MakeLower(); @@ -3845,17 +3866,16 @@ void CFinalSunDlg::InsertPrevFile(CString lpFilename) - for(i=3;i>0;i--) - { - theApp.m_Options.prev_maps[i]=theApp.m_Options.prev_maps[i-1]; + for (idx = 3; idx > 0; idx--) { + theApp.m_Options.prev_maps[idx]=theApp.m_Options.prev_maps[idx-1]; char e[10]; - itoa(i, e, 10); + itoa(idx, e, 10); - Options.sections["Files"].values[e]=theApp.m_Options.prev_maps[i]; + Options.SetString("Files", e, theApp.m_Options.prev_maps[idx]); } theApp.m_Options.prev_maps[0]=lpFilename; - Options.sections["Files"].values["0"]=theApp.m_Options.prev_maps[0]; + Options.SetString("Files", "0", theApp.m_Options.prev_maps[0]); @@ -3907,7 +3927,7 @@ void CFinalSunDlg::OpenMap(LPCSTR lpFilename) FSunPackLib::XCC_ExtractFile(pktFile, extractFile, hMix); m_PKTHeader.LoadFile(extractFile, TRUE); - fileToOpen=m_PKTHeader.sections["MultiMaps"].values["1"]+".map"; + fileToOpen = m_PKTHeader.GetString("MultiMaps", "1") + ".map"; @@ -3924,7 +3944,8 @@ void CFinalSunDlg::OpenMap(LPCSTR lpFilename) CIniFile f; f.InsertFile(fileToOpen, "Map"); - if((f.sections["Map"].values["Theater"]==THEATER0 && theApp.m_Options.bDoNotLoadTemperateGraphics) || (f.sections["Map"].values["Theater"]==THEATER1 && theApp.m_Options.bDoNotLoadSnowGraphics)) + auto const& theaterType = f.GetString("Map", "Theater"); + if((theaterType ==THEATER0 && theApp.m_Options.bDoNotLoadTemperateGraphics) || (theaterType ==THEATER1 && theApp.m_Options.bDoNotLoadSnowGraphics)) { MessageBox("You have selected to don´t show temperate or snow theater, but this map uses this theater. You cannot load it without restarting FinalSun/FinalAlert 2 with this theater enabled.", "Error"); return; @@ -3967,21 +3988,21 @@ void CFinalSunDlg::OpenMap(LPCSTR lpFilename) { int fielddata_size=Map->GetIsoSize()*Map->GetIsoSize(); - int i; - for(i=0;iGetFielddataAt(i)->wGround; + int gr=Map->GetFielddataAt(idx)->wGround; if(gr==0xFFFF) gr=0; if(gr>=(*tiledata_count)) { - Map->SetTileAt(i, 0, 0); + Map->SetTileAt(idx, 0, 0); } else { - if((*tiledata)[gr].wTileCount<=Map->GetFielddataAt(i)->bSubTile) + if((*tiledata)[gr].wTileCount<=Map->GetFielddataAt(idx)->bSubTile) { - Map->SetTileAt(i, 0, 0); + Map->SetTileAt(idx, 0, 0); } } } @@ -4056,18 +4077,15 @@ void CFinalSunDlg::OnOptionsSmoothzoom() Options.LoadFile(u8AppDataPath + "\\FinalAlert.ini"); #endif - if (GetMenu()->GetMenuState(ID_OPTIONS_SMOOTHZOOM, MF_BYCOMMAND) & MF_CHECKED) - { + if (GetMenu()->GetMenuState(ID_OPTIONS_SMOOTHZOOM, MF_BYCOMMAND) & MF_CHECKED) { GetMenu()->CheckMenuItem(ID_OPTIONS_SMOOTHZOOM, MF_BYCOMMAND | MF_UNCHECKED); theApp.m_Options.viewScaleUseSteps = true; - } - else - { + } else { GetMenu()->CheckMenuItem(ID_OPTIONS_SMOOTHZOOM, MF_BYCOMMAND | MF_CHECKED); theApp.m_Options.viewScaleUseSteps = false; } - Options.sections["UserInterface"].values["ViewScaleUseSteps"] = theApp.m_Options.viewScaleUseSteps ? "1" : "0"; + Options.SetBool("UserInterface", "ViewScaleUseSteps", theApp.m_Options.viewScaleUseSteps); #ifndef RA2_MODE Options.SaveFile(u8AppDataPath + "\\FinalSun.ini"); @@ -4107,7 +4125,7 @@ void CFinalSunDlg::OnOptionsUsedefaultmousecursor() m_hArrowCursor = LoadCursor(NULL, IDC_ARROW); } - Options.sections["UserInterface"].values["UseDefaultMouseCursor"] = theApp.m_Options.useDefaultMouseCursor ? "1" : "0"; + Options.SetBool("UserInterface", "UseDefaultMouseCursor", theApp.m_Options.useDefaultMouseCursor); #ifndef RA2_MODE Options.SaveFile(u8AppDataPath + "\\FinalSun.ini"); diff --git a/MissionEditor/FinalSunDlg.h b/MissionEditor/FinalSunDlg.h index 20081c1..54bbb4c 100644 --- a/MissionEditor/FinalSunDlg.h +++ b/MissionEditor/FinalSunDlg.h @@ -109,7 +109,7 @@ public: //{{AFX_VIRTUAL(CFinalSunDlg) public: virtual BOOL OnChildNotify(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pLResult); - virtual int DoModal(); + virtual INT_PTR DoModal(); protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV-Unterstützung virtual BOOL OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult); diff --git a/MissionEditor/GlobalsDlg.cpp b/MissionEditor/GlobalsDlg.cpp index 8c07264..61f32aa 100644 --- a/MissionEditor/GlobalsDlg.cpp +++ b/MissionEditor/GlobalsDlg.cpp @@ -100,19 +100,19 @@ void CGlobalsDlg::UpdateDialog() CString added=c; added+=" "; - if(ini.sections["VariableNames"].FindName(c)>=0) - { - added+=ini.sections["VariableNames"].values[c]; - } - else - { - bFailFind=TRUE; - added+=" No name"; + auto const& variableStr = ini.GetString("VariableNames", c); + if (!variableStr.IsEmpty()) { + added += variableStr; + } else { + bFailFind = TRUE; + added += " No name"; } m_Global.SetItemData(m_Global.AddString(added),i); - if(bFailFind) break; + if (bFailFind) { + break; + } } m_Global.SetCurSel(oldsel); @@ -136,8 +136,10 @@ void CGlobalsDlg::OnChangeDescription() if(m_Description.Find(",")>=0) m_Description.SetAt(m_Description.Find(","), 0); - if(ini.sections["VariableNames"].values[c].GetLength()==0) ini.sections["VariableNames"].values[c]="text,0"; - ini.sections["VariableNames"].values[c]=SetParam(ini.sections["VariableNames"].values[c], 0, m_Description); + if (ini.GetString( "VariableNames",c).IsEmpty()) { + ini.SetString("VariableNames", c, "text,0"); + } + ini.SetString("VariableNames", c, SetParam(ini.GetString("VariableNames", c), 0, m_Description)); // do not remove, Tiberian Sun seems to don´t like probably unused global numbers //if(m_Description.GetLength()==0) @@ -158,13 +160,13 @@ void CGlobalsDlg::OnSelchangeGlobal() char c[50]; itoa(curglob, c, 10); - if(ini.sections["VariableNames"].FindName(c)>=0) - { - m_Description=GetParam(ini.sections["VariableNames"].values[c],0); - m_Value.SetWindowText(GetParam(ini.sections["VariableNames"].values[c],1)); + auto const& variable = ini.GetString("VariableNames", c); + if (!variable.IsEmpty()) { + m_Description = GetParam(variable, 0); + m_Value.SetWindowText(GetParam(variable, 1)); + } else { + m_Description = ""; } - else - m_Description=""; UpdateData(FALSE); } @@ -197,14 +199,16 @@ void CGlobalsDlg::OnEditchangeValue() char c[50]; itoa(curglob, c, 10); - if(ini.sections["VariableNames"].FindName(c)<0) return; - + auto const& variable = ini.GetString("VariableNames", c); + if (variable.IsEmpty()) { + return; + } UpdateData(TRUE); str=GetParam(str, 0); TruncSpace(str); - ini.sections["VariableNames"].values[c]=SetParam(ini.sections["VariableNames"].values[c], 1, str); + ini.SetString("VariableNames", c, SetParam(variable, 1, str)); UpdateDialog(); } diff --git a/MissionEditor/Houses.cpp b/MissionEditor/Houses.cpp index d7dd396..8fef663 100644 --- a/MissionEditor/Houses.cpp +++ b/MissionEditor/Houses.cpp @@ -111,50 +111,44 @@ void CHouses::UpdateDialog() ListHouses(m_Side, FALSE, TRUE); int i; - for(i=0;iGetIniFile(); - if(ini.sections.find(MAPHOUSES)==ini.sections.end() && ini.sections.size()>0) - { + if(!ini.TryGetSection(MAPHOUSES) && ini.Size()>0) { // MessageBox("No houses do exist, if you want to use houses, you should use ""Prepare houses"" before doing anything else."); } - else - { + else { m_HumanPlayer.AddString("None"); m_HumanPlayer.SetCurSel(0); - for(i=0;iIsMultiplayer()) { - ini.sections["Basic"].values["MultiplayerOnly"]="1"; + ini.SetInteger("Basic", "MultiplayerOnly", 1); - int i; - for (i=0;i0) - { - MessageBox("There are already houses in your map. You need to delete these first."); - return; - } + if (ini[MAPHOUSES].Size() > 0) { + MessageBox("There are already houses in your map. You need to delete these first."); + return; } - int i; - for(i=0;iGetIniFile(); - if(ini.sections.find(name)!=ini.sections.end()) - { - MessageBox(((CString)"Sorry this name is not available. " + name + (CString)" is already used in the map file. You need to use another name.")); + if (ini.TryGetSection(name)) { + MessageBox("Sorry this name is not available. " + name + " is already used in the map file. You need to use another name."); return; } - if(ini.sections.find(TranslateHouse(name))!=ini.sections.end()) - { - MessageBox(((CString)"Sorry this name is not available. " + name + (CString)" is already used in the map file. You need to use another name.")); + if (ini.TryGetSection(TranslateHouse(name))) { + MessageBox("Sorry this name is not available. " + name + " is already used in the map file. You need to use another name."); return; } #ifdef RA2_MODE CNewRA2HouseDlg dlg; - if(dlg.DoModal()==IDCANCEL) return; + if (dlg.DoModal() == IDCANCEL) { + return; + } #endif int c; @@ -331,17 +315,21 @@ void CHouses::AddHouse(const char *name) { char k[50]; itoa(c,k,10); - if(ini.sections[MAPHOUSES].values.find(k)==ini.sections[MAPHOUSES].values.end()) - pos=c; - if(pos!=-1) break; + if (!ini[MAPHOUSES].Exists(k)) { + pos = c; + } + if (pos != -1) { + break; + } } #ifdef RA2_MODE for(c=0;c>-1;c++) { char k[50]; itoa(c,k,10); - if(ini.sections[HOUSES].values.find(k)==ini.sections[HOUSES].values.end()) + if (!ini[HOUSES].Exists(k)) { pos2=c; + } if(pos2!=-1) break; } #endif @@ -349,72 +337,77 @@ void CHouses::AddHouse(const char *name) char k[50]; itoa(pos,k,10); - ini.sections[MAPHOUSES].values[k]=TranslateHouse(name); + auto const translatedHouseName = TranslateHouse(name); + ini.SetString(MAPHOUSES, k, translatedHouseName); CString country; - country=name; + country = name; country.Replace(" House", ""); country.Replace("House",""); - if(country.Find(" ")>=0) country.Replace(" ", "_"); //=country.Left(country.Find(" ")); + if (country.Find(" ") >= 0) { + country.Replace(" ", "_"); //=country.Left(country.Find(" ")); + } #ifdef RA2_MODE - itoa(pos2, k, 10); - ini.sections[HOUSES].values[k]=country; + _itoa(pos2, k, 10); + ini.SetString(HOUSES, k, country); #endif - - ini.sections[TranslateHouse(name)].values["IQ"]="0"; - ini.sections[TranslateHouse(name)].values["Edge"]="West"; - ini.sections[TranslateHouse(name)].values["Allies"]=TranslateHouse(name); + ini.SetInteger(translatedHouseName, "IQ", 0); + ini.SetString(translatedHouseName, "Edge", "West"); + ini.SetString(translatedHouseName, "Allies", translatedHouseName); - CString side=name; + CString side = name; #ifdef RA2_MODE - side=rules.sections[TranslateHouse(dlg.m_Country)].values["Side"]; + side = rules.GetString(TranslateHouse(dlg.m_Country), "Side"); #endif - if(strstr(name, "Nod")!=NULL) - { + if (strstr(name, "Nod") != NULL) { #ifndef RA2_MODE - ini.sections[TranslateHouse(name)].values["Side"]="Nod"; + ini.sections[translatedHouseName].values["Side"]="Nod"; #endif - ini.sections[TranslateHouse(name)].values["Color"]="DarkRed"; - if(name!="Nod") ini.sections[name].values["Allies"]+=",Nod"; - } - else - { + ini.SetString(translatedHouseName, "Color", "DarkRed"); + if (name != "Nod") { + ini.SetString(name, "Allies", ini.GetString(name, "Allies") + ",Nod"); + } + } else { #ifndef RA2_MODE - ini.sections[TranslateHouse(name)].values["Side"]="GDI"; + ini.sections[translatedHouseName].values["Side"]="GDI"; #endif - ini.sections[TranslateHouse(name)].values["Color"]="Gold"; - if(name!="GDI") ini.sections[TranslateHouse(name)].values["Allies"]+=",GDI"; + ini.SetString(translatedHouseName, "Color", "Gold"); + if (name != "GDI") { + ini.SetString(translatedHouseName, "Allies", ini.GetString(translatedHouseName, "Allies") + ",GDI"); + } } - ini.sections[TranslateHouse(name)].values["Credits"]="0"; + ini.SetInteger(translatedHouseName, "Credits", 0); #ifndef RA2_MODE - ini.sections[TranslateHouse(name)].values["ActsLike"]="0"; + ini.SetInteger(translatedHouseName, "ActsLike", 0); #else - ini.sections[TranslateHouse(name)].values["Country"]=TranslateHouse(country); + ini.SetString(translatedHouseName, "Country", TranslateHouse(country)); #endif - ini.sections[TranslateHouse(name)].values["NodeCount"]="0"; - ini.sections[TranslateHouse(name)].values["TechLevel"]="10"; - ini.sections[TranslateHouse(name)].values["PercentBuilt"]="100"; - ini.sections[TranslateHouse(name)].values["PlayerControl"]="no"; + ini.SetInteger(translatedHouseName, "NodeCount", 0); + ini.SetInteger(translatedHouseName, "TechLevel", 10); + ini.SetInteger(translatedHouseName, "PercentBuilt", 100); + ini.SetBool(translatedHouseName, "PlayerControl", false); #ifdef RA2_MODE - dlg.m_Country=TranslateHouse(dlg.m_Country); // just to make sure... - country=TranslateHouse(country); - ini.sections[country].values["ParentCountry"]=dlg.m_Country; - ini.sections[country].values["Name"]=country; - ini.sections[country].values["Suffix"]=rules.sections[dlg.m_Country].values["Suffix"]; - ini.sections[country].values["Prefix"]=rules.sections[dlg.m_Country].values["Prefix"]; - ini.sections[country].values["Color"]=rules.sections[dlg.m_Country].values["Color"]; - ini.sections[country].values["Side"]=rules.sections[dlg.m_Country].values["Side"]; - ini.sections[country].values["SmartAI"]=rules.sections[dlg.m_Country].values["SmartAI"]; - ini.sections[country].values["CostUnitsMult"]="1"; + dlg.m_Country = TranslateHouse(dlg.m_Country); // just to make sure... + country = TranslateHouse(country); + ini.SetString(country, "ParentCountry", dlg.m_Country); + ini.SetString(country, "Name", country); + ini.SetString(country, "Suffix", rules.GetString(dlg.m_Country, "Suffix")); + ini.SetString(country, "Prefix", rules.GetString(dlg.m_Country, "Prefix")); + ini.SetString(country, "Color", rules.GetString(dlg.m_Country, "Color")); + ini.SetString(country, "Side", rules.GetString(dlg.m_Country, "Side")); + ini.SetString(country, "SmartAI", rules.GetString(dlg.m_Country, "SmartAI")); + ini.SetInteger(country, "CostUnitsMult", 1); #endif int cusel=m_houses.GetCurSel(); UpdateDialog(); ((CFinalSunDlg*)theApp.m_pMainWnd)->UpdateDialogs(); - if(cusel!=-1)m_houses.SetCurSel(cusel); + if (cusel != -1) { + m_houses.SetCurSel(cusel); + } } void CHouses::OnShowWindow(BOOL bShow, UINT nStatus) @@ -423,10 +416,8 @@ void CHouses::OnShowWindow(BOOL bShow, UINT nStatus) CIniFile& ini=Map->GetIniFile(); - if(bShow) - { - if(ini.sections.find(MAPHOUSES)==ini.sections.end() && ini.sections.size()>0) - { + if (bShow) { + if (!ini.TryGetSection(MAPHOUSES) && ini.Size() > 0) { #ifndef RA2_MODE MessageBox("No houses do exist, if you want to use houses, you should use ""Prepare houses"" before doing anything else. Note that in a multiplayer map independent computer players cannot be created by using the names GDI and Nod for the house. Just use something like GDI_AI."); #else @@ -434,23 +425,20 @@ void CHouses::OnShowWindow(BOOL bShow, UINT nStatus) #endif } + } else { + // call all KillFocus ! + OnKillfocusIq(); + OnEditchangeActslike(); + OnKillfocusAllies(); + OnKillfocusColor(); + OnKillfocusCredits(); + OnKillfocusEdge(); + OnKillfocusNodecount(); + OnKillfocusPercentbuilt(); + OnKillfocusPlayercontrol(); + OnKillfocusSide(); + OnKillfocusTechlevel(); } - else - { - // call all KillFocus ! - OnKillfocusIq(); - OnEditchangeActslike(); - OnKillfocusAllies(); - OnKillfocusColor(); - OnKillfocusCredits(); - OnKillfocusEdge(); - OnKillfocusNodecount(); - OnKillfocusPercentbuilt(); - OnKillfocusPlayercontrol(); - OnKillfocusSide(); - OnKillfocusTechlevel(); - } - } void CHouses::OnAddhouse() @@ -468,33 +456,31 @@ void CHouses::OnDeletehouse() CIniFile& ini=Map->GetIniFile(); int cusel; - cusel=m_houses.GetCurSel(); - if(cusel==-1) return; + cusel = m_houses.GetCurSel(); + if (cusel == -1) { + return; + } CString name; CString uiname; m_houses.GetLBText(cusel, name); uiname=name; - name=TranslateHouse(name); + name = TranslateHouse(name); CString str=GetLanguageStringACP("DeleteHouse"); - str=TranslateStringVariables(1, str, uiname); - if(MessageBox(str,GetLanguageStringACP("DeleteHouseCap"),MB_YESNO)==IDNO) return; - - ini.sections.erase((LPCTSTR)name); - - int i; - for(i=0;iUpdateDialogs(); UpdateDialog(); @@ -514,11 +500,9 @@ void CHouses::OnKillfocusIq() m_houses.GetLBText(cusel, name); name=TranslateHouse(name); - CIniFileSection& s=ini.sections[(LPCTSTR)name]; - CString t; m_IQ.GetWindowText(t); - s.values["IQ"]=t; + ini.SetString(name, "IQ", t); } void CHouses::OnKillfocusEdge() @@ -535,11 +519,9 @@ void CHouses::OnKillfocusEdge() m_houses.GetLBText(cusel, name); name=TranslateHouse(name); - CIniFileSection& s=ini.sections[(LPCTSTR)name]; - CString t; m_Edge.GetWindowText(t); - s.values["Edge"]=t; + ini.SetString(name, "Edge", t); } void CHouses::OnKillfocusSide() @@ -556,15 +538,13 @@ void CHouses::OnKillfocusSide() m_houses.GetLBText(cusel, name); name=TranslateHouse(name); - CIniFileSection& s=ini.sections[(LPCTSTR)name]; - CString t; m_Side.GetWindowText(t); t=TranslateHouse(t); #ifndef RA2_MODE - s.values["Side"]=t; + ini.SetString(name, "Side", t); #else - s.values["Country"]=t; + ini.SetString(name, "Country", t); #endif } @@ -582,11 +562,9 @@ void CHouses::OnKillfocusColor() m_houses.GetLBText(cusel, name); name=TranslateHouse(name); - CIniFileSection& s=ini.sections[(LPCTSTR)name]; - CString t; m_Color.GetWindowText(t); - s.values["Color"]=t; + ini.SetString(name, "Color", t); //Map->UpdateIniFile(MAPDATA_UPDATE_FROM_INI); // MW fix: Only update structures @@ -612,12 +590,10 @@ void CHouses::OnKillfocusAllies() m_houses.GetLBText(cusel, name); name=TranslateHouse(name); - CIniFileSection& s=ini.sections[(LPCTSTR)name]; - CString t; m_Allies.GetWindowText(t); t=TranslateHouse(t); - s.values["Allies"]=t; + ini.SetString(name, "Allies", t); } void CHouses::OnKillfocusCredits() @@ -634,11 +610,9 @@ void CHouses::OnKillfocusCredits() m_houses.GetLBText(cusel, name); name=TranslateHouse(name); - CIniFileSection& s=ini.sections[(LPCTSTR)name]; - CString t; m_Credits.GetWindowText(t); - s.values["Credits"]=t; + ini.SetString(name, "Credits", t); } void CHouses::OnEditchangeActslike() @@ -655,15 +629,11 @@ void CHouses::OnEditchangeActslike() m_houses.GetLBText(cusel, name); name=TranslateHouse(name); - - - CIniFileSection& s=ini.sections[(LPCTSTR)name]; - CString t; m_ActsLike.GetWindowText(t); TruncSpace(t); t=TranslateHouse(t); - s.values["ActsLike"]=t; + ini.SetString(name, "ActsLike", t); } void CHouses::OnKillfocusNodecount() @@ -680,11 +650,9 @@ void CHouses::OnKillfocusNodecount() m_houses.GetLBText(cusel, name); name=TranslateHouse(name); - CIniFileSection& s=ini.sections[(LPCTSTR)name]; - CString t; m_Nodecount.GetWindowText(t); - s.values["NodeCount"]=t; + ini.SetString(name, "NodeCount", t); } void CHouses::OnKillfocusTechlevel() @@ -701,11 +669,9 @@ void CHouses::OnKillfocusTechlevel() m_houses.GetLBText(cusel, name); name=TranslateHouse(name); - CIniFileSection& s=ini.sections[(LPCTSTR)name]; - CString t; m_TechLevel.GetWindowText(t); - s.values["TechLevel"]=t; + ini.SetString(name, "TechLevel", t); } void CHouses::OnKillfocusPercentbuilt() @@ -722,11 +688,9 @@ void CHouses::OnKillfocusPercentbuilt() m_houses.GetLBText(cusel, name); name=TranslateHouse(name); - CIniFileSection& s=ini.sections[(LPCTSTR)name]; - CString t; m_PercentBuilt.GetWindowText(t); - s.values["PercentBuilt"]=t; + ini.SetString(name, "PercentBuilt", t); } void CHouses::OnKillfocusPlayercontrol() @@ -743,11 +707,9 @@ void CHouses::OnKillfocusPlayercontrol() m_houses.GetLBText(cusel, name); name=TranslateHouse(name); - CIniFileSection& s=ini.sections[(LPCTSTR)name]; - CString t; m_PlayerControl.GetWindowText(t); - s.values["PlayerControl"]=t; + ini.SetString(name, "PlayerControl", t); } void CHouses::OnSelchangeHumanplayer() @@ -758,14 +720,12 @@ void CHouses::OnSelchangeHumanplayer() m_HumanPlayer.GetLBText(m_HumanPlayer.GetCurSel(),pl); pl=TranslateHouse(pl); - if(pl.GetLength()==0 || pl=="None") - { - ini.sections["Basic"].values.erase("Player"); - } - else - { - ini.sections["Basic"].values["Player"]=(LPCTSTR)pl; + if(pl.GetLength()==0 || pl=="None") { + ini.RemoveValueByKey("Basic", "Player"); + return; } + + ini.SetString("Basic", "Player", pl); } void CHouses::OnSelchangeActslike() @@ -780,15 +740,11 @@ void CHouses::OnSelchangeActslike() m_houses.GetLBText(cusel, name); name=TranslateHouse(name); - - - CIniFileSection& s=ini.sections[(LPCTSTR)name]; - CString t; m_ActsLike.GetLBText(m_ActsLike.GetCurSel(),t); TruncSpace(t); t=TranslateHouse(t); - s.values["ActsLike"]=t; + ini.SetString(name, "ActsLike", t); } void CHouses::UpdateStrings() diff --git a/MissionEditor/Houses.h b/MissionEditor/Houses.h index 98ffd5e..5e92a26 100644 --- a/MissionEditor/Houses.h +++ b/MissionEditor/Houses.h @@ -37,7 +37,7 @@ class CHouses : public CDialog // Konstruktion public: void UpdateStrings(); - void AddHouse(const char* name); + void AddHouse(const CString& name); void UpdateDialog(); CHouses(); ~CHouses(); diff --git a/MissionEditor/ImportINI.cpp b/MissionEditor/ImportINI.cpp index d42f3e9..82025ab 100644 --- a/MissionEditor/ImportINI.cpp +++ b/MissionEditor/ImportINI.cpp @@ -90,15 +90,18 @@ BOOL CImportINI::OnInitDialog() CIniFile inifile; inifile.LoadFile(this->m_FileName); - if(inifile.sections.size()<1){MessageBox("File does not have any ini content, abort.","Error");EndDialog(IDCANCEL);return TRUE;} + if (inifile.Size() < 1) { + MessageBox("File does not have any ini content, abort.", "Error"); + EndDialog(IDCANCEL); + return TRUE; + } - m_inicount=inifile.sections.size(); + m_inicount = inifile.Size(); - int i; - for(i=0;iIsMapSection(*inifile.GetSectionName(i))) - m_Available.InsertString(-1, *inifile.GetSectionName(i)); + for (auto const& [secName, _] : inifile) { + if (!Map->IsMapSection(secName)) { + m_Available.InsertString(-1, secName); + } } return TRUE; // return TRUE unless you set the focus to a control diff --git a/MissionEditor/IniFile.cpp b/MissionEditor/IniFile.cpp index 63c7a16..b803447 100644 --- a/MissionEditor/IniFile.cpp +++ b/MissionEditor/IniFile.cpp @@ -38,18 +38,8 @@ static char THIS_FILE[] = __FILE__; using namespace std; -bool SortDummy::operator()(const CString& x, const CString& y) const -{ - // the length is more important than spelling (numbers!!!)... - if (x.GetLength() < y.GetLength()) return true; - if (x.GetLength() == y.GetLength()) - { - if (x < y) return true; - } - - return false; - -} +const CIniFileSection CIniFile::EmptySection; +const CString CIniFileSection::EmptyValue; typedef map::iterator CIniI; typedef map::iterator SI; @@ -95,14 +85,12 @@ void CIniFile::Clear() CIniFileSection::CIniFileSection() { - values.clear(); - value_orig_pos.clear(); }; CIniFileSection::~CIniFileSection() { - values.clear(); - value_orig_pos.clear(); + value_pos.clear(); + value_pairs.clear(); }; WORD CIniFile::InsertFile(const CString& filename, const char* Section, BOOL bNoSpaces) @@ -158,16 +146,12 @@ WORD CIniFile::InsertFile(const std::string& filename, const char* Section, BOOL CString name = cLine.substr(0, equals).c_str(); CString value = cLine.substr(equals + 1, cLine.size() - equals - 1).c_str(); - int cuValueIndex = sections[cSec].values.size(); - if (bNoSpaces) { name.Trim(); value.Trim(); } - - sections[cSec].values[name] = value; - sections[cSec].value_orig_pos[name] = cuValueIndex; + sections[cSec].SetString(name, value); } } @@ -180,83 +164,6 @@ WORD CIniFile::InsertFile(const std::string& filename, const char* Section, BOOL return 0; } -const CIniFileSection* CIniFile::GetSection(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::GetSection(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 CIniFileSection* CIniFile::GetSection(const CString& section) const -{ - auto it = sections.find(section); - if (it == sections.end()) - return nullptr; - return &it->second; -} - -CIniFileSection* CIniFile::GetSection(const CString& section) -{ - auto it = sections.find(section); - if (it == sections.end()) - return nullptr; - return &it->second; -} - -const CString* CIniFileSection::GetValue(std::size_t index) const noexcept -{ - if (index > values.size() - 1) - return NULL; - - auto i = values.begin(); - for (auto e = 0;e < index;e++) - i++; - - return &i->second; -} - -CString* CIniFileSection::GetValue(std::size_t index) noexcept -{ - if (index > values.size() - 1) - return NULL; - - auto i = values.begin(); - for (auto e = 0; e < index; e++) { - if (i == values.end()) { - break; - } - i++; - } - if (i == values.end()) { - return nullptr; - } - - return &i->second; -} - -CString CIniFileSection::GetValueByName(const CString& valueName, const CString& defaultValue) const -{ - auto it = values.find(valueName); - return (it == values.end()) ? defaultValue : it->second; -} - const CString* CIniFile::GetSectionName(std::size_t index) const noexcept { if (index > sections.size() - 1) @@ -269,24 +176,6 @@ const CString* CIniFile::GetSectionName(std::size_t index) const noexcept return &(i->first); } -CString& CIniFileSection::AccessValueByName(const CString& valueName) -{ - return values[valueName]; -} - -const CString* CIniFileSection::GetValueName(std::size_t index) const noexcept -{ - if (index > values.size() - 1) - return NULL; - - auto i = values.begin(); - for (auto e = 0; e < index; ++e) - i++; - - - return &(i->first); -} - BOOL CIniFile::SaveFile(const CString& filename) const { return SaveFile(std::string(filename.GetString())); @@ -298,14 +187,10 @@ BOOL CIniFile::SaveFile(const std::string& Filename) const file.open(Filename, ios::out | ios::trunc); - int i; - for (i = 0;i < sections.size();i++) - { - file << "[" << (LPCTSTR)*GetSectionName(i) << "]" << endl; - int e; - for (e = 0;e < GetSection(i)->values.size();e++) - { - file << (LPCTSTR) * (GetSection(i)->GetValueName(e)) << "=" << (LPCTSTR)*GetSection(i)->GetValue(e) << endl; + for (auto const& sec : sections) { + file << "[" << sec.first << "]" << endl; + for (auto const& pair : sec.second) { + file << pair.first << "=" << pair.second << endl; } file << endl; } @@ -316,97 +201,32 @@ BOOL CIniFile::SaveFile(const std::string& Filename) const } -int CIniFileSection::FindValue(CString sval) const noexcept +int64_t CIniFileSection::FindValue(CString val) const noexcept { - int i; - auto it = values.cbegin(); - for (i = 0;i < values.size();i++) - { - if (sval == it->second) - return i; - it++; + for (size_t idx = 0; + idx < this->value_pairs.size(); + ++idx) { + if (this->value_pairs[idx].second == val) { + return idx; + } } return -1; } -int CIniFileSection::FindName(CString sval) const noexcept +int64_t CIniFileSection::FindIndex(const CString& key) const noexcept { - int i; - auto it = values.cbegin(); - for (i = 0;i < values.size();i++) - { - if (sval == it->first) - return i; - it++; + auto const it = this->value_pos.find(key); + if (it != this->value_pos.end()) { + return it->second; } return -1; } -void CIniFile::DeleteLeadingSpaces(BOOL bValueNames, BOOL bValues) -{ - int i; - for (i = 0;i < sections.size();i++) - { - CIniFileSection& sec = *GetSection(i); - int e; - for (e = 0;e < sec.values.size();e++) - { - if (bValues) sec.GetValue(e)->TrimLeft(); - if (bValueNames) - { - CString value = *sec.GetValue(e); - CString name = *sec.GetValueName(e); - - sec.values.erase(name); - name.TrimLeft(); - sec.values[name] = value; - } - } - } -} - -void CIniFile::DeleteEndingSpaces(BOOL bValueNames, BOOL bValues) -{ - int i; - for (i = 0;i < sections.size();i++) - { - CIniFileSection& sec = *GetSection(i); - int e; - for (e = 0;e < sec.values.size();e++) - { - if (bValues) sec.GetValue(e)->TrimRight(); - if (bValueNames) - { - //CString& name=(CString&)*sec.GetValueName(e); - //name.TrimRight(); - CString value = *sec.GetValue(e); - CString name = *sec.GetValueName(e); - - sec.values.erase(name); - name.TrimRight(); - sec.values[name] = value; - } - } - } -} - CString CIniFile::GetValueByName(const CString& sectionName, const CString& valueName, const CString& defaultValue) const { - auto section = GetSection(sectionName); - if (!section) + auto section = TryGetSection(sectionName); + 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 bc0b8b6..4e552ee 100644 --- a/MissionEditor/IniFile.h +++ b/MissionEditor/IniFile.h @@ -33,82 +33,220 @@ #include #include #include +#include +#include #include - +#include "IniHelper.h" using namespace std; class SortDummy { public: - bool operator() (const CString&, const CString&) const; + bool operator()(const CString& x, const CString& y) const + { + // the length is more important than spelling (numbers!!!)... + if (x.GetLength() < y.GetLength()) { + return true; + } + if (x.GetLength() == y.GetLength()) { + if (x < y) { + return true; + } + } + return false; + } }; class CIniFileSection { + static const CString EmptyValue; public: + CIniFileSection(); virtual ~CIniFileSection(); - CString GetValueByName(const CString& name, const CString& defaultValue = CString()) const; - CString& AccessValueByName(const CString& name); + [[deprecated("instead use GetString or TryGetString")]] + const CString& AccessValueByName(const CString& name) const { + return GetString(name); + } - auto begin() noexcept - { - return values.begin(); + auto const& Nth(size_t index) const { + ASSERT(index < value_pairs.size()); + return this->value_pairs[index]; + } + int64_t FindIndex(const CString& key) const noexcept; + int64_t FindValue(CString val) const noexcept; + + const CString& operator[](const CString& key) const { + return this->GetString(key); + } + + const CString* TryGetString(const CString& key) const { + auto const it = value_pos.find(key); + if (it != value_pos.end()) { + return &this->value_pairs[it->second].second; + } + 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; + } + return EmptyValue; + } + CString GetStringOr(const CString& key, const CString& defaultValue) const { + auto const it = value_pos.find(key); + if (it != value_pos.end()) { + return this->value_pairs[it->second].second; + } + return defaultValue; + } + + int GetInteger(const CString& key, int def = 0) const { + return INIHelper::StringToInteger(this->GetString(key), def); + } + + float GetFloat(const CString& key, float def = 0.0) const { + return INIHelper::StringToFloat(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 { + auto const it = value_pos.find(key); + return it != value_pos.end(); + } + bool HasValue(const CString& val) const { + return this->FindValue(val) >= 0; + } + + void SetString(const CString& key, const CString& value) { + return this->SetString(key, CString(value)); + } + + void SetString(const CString& key, CString&& value) { + auto const it = value_pos.find(key); + // new, never had one + if (it == value_pos.end()) { + this->Insert(key, std::move(value)); + return; + } + value_pairs[it->second].second = std::move(value); + } + + void SetInteger(const CString& key, const int val) { + this->SetString(key, INIHelper::ToString(val)); + } + + void SetBool(const CString& key, const bool val) { + this->SetString(key, INIHelper::ToString(val)); + } + + 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()); + // delete from record first; + auto const& pair = value_pairs.at(idx); + ASSERT(value_pos.erase(pair.first) == 1); + value_pairs.erase(value_pairs.begin() + idx); + // now update all key-pos indexing, dec 1 + for (auto affectedIdx = idx; affectedIdx < value_pairs.size(); ++affectedIdx) { + auto const& kvPair = value_pairs[affectedIdx]; + auto const it = value_pos.find(kvPair.first); + ASSERT(it != value_pos.end()); + it->second--; + } + } + + void RemoveByKey(const CString& key) { + auto const idx = this->FindIndex(key); + if (idx >= 0) { + RemoveAt(idx); + } + } + + void RemoveValue(const CString& val) { + auto const idx = this->FindValue(val); + if (idx >= 0) { + RemoveAt(idx); + } } auto begin() const noexcept { - return values.begin(); - } - - auto end() noexcept - { - return values.end(); + return value_pairs.begin(); } auto end() const noexcept { - return values.end(); + return value_pairs.end(); } [[deprecated("instead use iterators or for_each")]] - int GetValueOrigPos(int index) const noexcept; + // get key + const CString* GetValueName(std::size_t index) const noexcept { + return &Nth(index).first; + } - [[deprecated("instead use iterators or for_each")]] - int FindName(CString sval) const noexcept; - - [[deprecated("instead use iterators or for_each")]] - int FindValue(CString sval) const noexcept; - - [[deprecated("instead use iterators or for_each")]] - const CString* GetValueName(std::size_t index) const noexcept; - - [[deprecated("instead use iterators or for_each")]] - const CString* GetValue(std::size_t index) const noexcept; - - [[deprecated("instead use iterators or for_each")]] - CString* GetValue(std::size_t index) noexcept; - -public: - map values; - map value_orig_pos; +private: + map value_pos{}; + vector> value_pairs{};// sequenced + mutable bool isRegistry{false}; }; class CIniFile { + using StorageMap = map; + + static const CIniFileSection EmptySection; + public: - void DeleteEndingSpaces(BOOL bValueNames, BOOL bValues); - void DeleteLeadingSpaces(BOOL bValueNames, BOOL bValues); - - const CString* GetSectionName(std::size_t Index) const noexcept; - const CIniFileSection* GetSection(std::size_t index) const; - CIniFileSection* GetSection(std::size_t index); - const CIniFileSection* GetSection(const CString& section) const; - CIniFileSection* GetSection(const CString& section); + CIniFile(CIniFile&& rhs) noexcept : + m_filename(std::move(rhs.m_filename)), + sections(std::move(rhs.sections)) + {} + CIniFile(const CIniFile& rhs) noexcept : + m_filename(rhs.m_filename), + sections(rhs.sections) + {} + + CIniFile& operator=(CIniFile&& rhs) noexcept { + new (this)CIniFile(std::move(rhs)); + return *this; + } + CIniFile& operator=(const CIniFile& rhs) noexcept { + new (this)CIniFile(rhs); + return *this; + } + + [[deprecated("instead use GetString")]] CString GetValueByName(const CString& sectionName, const CString& valueName, const CString& defaultValue) const; void Clear(); WORD InsertFile(const CString& filename, const char* Section, BOOL bNoSpaces = FALSE); @@ -118,6 +256,104 @@ public: WORD LoadFile(const CString& filename, BOOL bNoSpaces = FALSE); WORD LoadFile(const std::string& filename, BOOL bNoSpaces = FALSE); + // ================ Section interfaces ================ + + const CString* GetSectionName(std::size_t Index) const noexcept; + const CIniFileSection* TryGetSection(const CString& section) const + { + auto pMutThis = const_cast>*>(this); + return pMutThis->TryGetSection(section); + } + + CIniFileSection* TryGetSection(const CString& section) + { + auto it = sections.find(section); + if (it != sections.end()) { + return &it->second; + + } + return nullptr; + } + + const CIniFileSection& GetSection(const CString& section) const { + if (auto found = this->TryGetSection(section)) { + return *found; + } + return EmptySection; + } + + const CIniFileSection& operator[](const CString& section) const { + return this->GetSection(section); + } + + bool DeleteSection(const CString& section) { + return sections.erase(section) > 0; + } + + typename StorageMap::iterator DeleteAt(const StorageMap::iterator pos) { + return sections.erase(pos); + } + + // ============= Reader and Helper converter ============================ + const CString& GetString(const CString& section, const CString& key) const { + return GetSection(section).GetString(key); + } + const CString GetStringOr(const CString& section, const CString& key, const CString& def) const { + return GetSection(section).GetStringOr(key, def); + } + const bool GetBool(const CString& section, const CString& key, bool def = false) const { + 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); + } + + // ============== Writer and Helper converter ============================ + CIniFileSection& AddSection(CString&& sectionName) { + auto const ret = this->sections.insert({ std::move(sectionName), {}}); + return ret.first->second; + } + CIniFileSection& AddSection(const CString& sectionName) { + return this->AddSection(CString(sectionName)); + } + + void SetSection(const CString& sectionName, const CIniFileSection& sec) { + sections.insert_or_assign(sectionName, sec); + } + + void SetString(const CString& section, const CString& key, CString&& value) { + auto const it = sections.find(section); + if (it != sections.end()) { + it->second.SetString(key, value); + return; + } + auto&& newSec = CIniFileSection{}; + newSec.SetString(key, value); + ASSERT(sections.insert({ section, std::move(newSec) }).second == true); + } + + void SetString(const CString& section, const CString& key, const CString& value) { + 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)); + } + void SetInteger(const CString& section, const CString& key, const int value) { + this->SetString(section, key, INIHelper::ToString(value)); + } + + void RemoveValueByKey(const CString& section, const CString& key) { + if (auto pSec = this->TryGetSection(section)) { + pSec->RemoveByKey(key); + } + } + + // ================= Iterator Related ============================= + + auto Size() const noexcept { + return this->sections.size(); + } auto begin() noexcept { @@ -139,12 +375,12 @@ public: return sections.end(); } - map sections; CIniFile(); virtual ~CIniFile(); private: std::string m_filename; + StorageMap sections; }; #endif // !defined(AFX_INIFILE_H__96455620_6528_11D3_99E0_DB2A1EF71411__INCLUDED_) diff --git a/MissionEditor/IniHelper.h b/MissionEditor/IniHelper.h new file mode 100644 index 0000000..868e6c4 --- /dev/null +++ b/MissionEditor/IniHelper.h @@ -0,0 +1,65 @@ +#pragma once +#include +#include + +class INIHelper +{ +public: + static bool StringToBool(const CString& str, bool def) + { + switch (toupper(static_cast(*str))) { + case '1': + case 'T': + case 'Y': + return true; + case '0': + case 'F': + case 'N': + return false; + default: + return def; + } + } + static int StringToInteger(const CString& str, int def) + { + int ret = 0; + if (sscanf_s(str, "%d", &ret) == 1) { + return ret; + } + return def; + } + static double StringToDouble(const CString& str, double def) + { + double ret = 0; + if (sscanf_s(str, "%lf", &ret) == 1) { + if (strchr(str, '%')) { + ret *= 0.01; + } + return ret; + } + return def; + } + static float StringToFloat(const CString& str, float def) + { + return static_cast(StringToDouble(str, 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[] = { "no", "yes" }; + return result[origin]; + } + + template<> + static CString ToString(const int& origin) + { + char buffer[0x100]; + _itoa_s(origin, buffer, 10); + buffer[sizeof buffer - 1] = '\0'; + return buffer; + } +}; \ No newline at end of file diff --git a/MissionEditor/InputBox.cpp b/MissionEditor/InputBox.cpp index 6ebbf6c..44cd9ce 100644 --- a/MissionEditor/InputBox.cpp +++ b/MissionEditor/InputBox.cpp @@ -44,10 +44,11 @@ CString InputBox(const char* Sentence, const char* Caption) CInputBox inp; inp.SetCaption(Caption); inp.SetSentence(Sentence); - char* res=(char*) inp.DoModal(); - CString cstr=res; - - return cstr; + if (inp.DoModal()) { + return inp.GetResult(); + } + + return ""; } CInputBox::CInputBox(CWnd* pParent /*=NULL*/) @@ -75,22 +76,22 @@ END_MESSAGE_MAP() -void CInputBox::OnOK() +void CInputBox::OnOK() { CString text; GetDlgItem(IDC_VAL)->GetWindowText(text); - if(text.GetLength()==0){EndDialog(NULL);}; + if (text.GetLength() == 0) + EndDialog(false); - char* str; - str=new(char[text.GetLength()]); - strcpy(str, (LPCTSTR)text); - EndDialog((int)str); + m_Result = text; + + EndDialog(true); } void CInputBox::OnCancel() { - EndDialog(NULL); + EndDialog(false); } void CInputBox::SetCaption(CString Caption) diff --git a/MissionEditor/InputBox.h b/MissionEditor/InputBox.h index ddb6bb0..4612833 100644 --- a/MissionEditor/InputBox.h +++ b/MissionEditor/InputBox.h @@ -47,7 +47,7 @@ public: enum { IDD = IDD_INPUTBOX }; //}}AFX_DATA - + const CString& GetResult() const { return m_Result; } // Überschreibungen // Vom Klassen-Assistenten generierte virtuelle Funktionsüberschreibungen //{{AFX_VIRTUAL(CInputBox) @@ -68,6 +68,7 @@ protected: private: CString m_Text; CString m_Caption; + CString m_Result; }; //{{AFX_INSERT_LOCATION}} diff --git a/MissionEditor/IsoView.cpp b/MissionEditor/IsoView.cpp index 01da86d..a1c71a2 100644 --- a/MissionEditor/IsoView.cpp +++ b/MissionEditor/IsoView.cpp @@ -2859,7 +2859,7 @@ void CIsoView::OnLButtonDown(UINT nFlags, CPoint point) dlg.m_tag = tag; dlg.m_tag += " ("; - dlg.m_tag += GetParam(Map->GetIniFile().sections["Tags"].values[(LPCTSTR)tag], 1); + dlg.m_tag += GetParam(Map->GetIniFile().GetString("Tags", tag), 1); dlg.m_tag += ")"; if (dlg.DoModal() == IDCANCEL) return; @@ -3499,28 +3499,20 @@ COLORREF CIsoView::GetColor(const char* house, const char* vcolor) CIniFile& ini = Map->GetIniFile(); if (house && strlen(house)) { - if (ini.sections.find(house) != ini.sections.end()) - { - color = ini.sections[house].values["Color"]; + auto const& localColorDef = ini.GetString(house, "Color"); + if (!localColorDef.IsEmpty()) { + color = localColorDef; + } else { + color = rules.GetString(house, "Color"); } - else - color = rules.sections[house].values["Color"]; } if (vcolor) color = vcolor; - if (color) - { + if (color) { CString colorValues; - if (ini.sections.contains("Colors")) - { - colorValues = ini.sections["Colors"].GetValueByName(color); - } - if (colorValues.IsEmpty() && rules.sections.contains("Colors")) - { - colorValues = rules.sections["Colors"].GetValueByName(color); - } + colorValues = ini.GetStringOr("Colors", color, rules.GetString("Colors", color)); auto colorArray = SplitParams(colorValues); if (colorArray.size() == 3) { @@ -4335,8 +4327,10 @@ void CIsoView::UpdateStatusBar(int x, int y) DWORD pos; Map->GetCelltagData(n, &type, &pos); CIniFile& ini = Map->GetIniFile(); - if (ini.sections["Tags"].values.find(type) != ini.sections["Tags"].values.end()) - name = GetParam(ini.sections["Tags"].values[type], 1); + auto const tagStr = ini.GetString("Tags", type); + if (!tagStr.IsEmpty()) { + name = GetParam(tagStr, 1); + } statusbar += GetLanguageStringACP("CellTagStatus"); statusbar += name; @@ -5222,7 +5216,7 @@ void CIsoView::PlaceCurrentObjectAt(int x, int y) } -void CIsoView::OnTimer(UINT nIDEvent) +void CIsoView::OnTimer(UINT_PTR nIDEvent) { // theApp.m_loading->FreeAll(); // theApp.m_loading->InitPics(); @@ -5681,7 +5675,7 @@ void CIsoView::DrawMap() // Now left, right, top & bottom contain the needed values - DWORD MM_heightstart = tilesets_start[atoi((*tiles).sections["General"].values["HeightBase"])]; + DWORD MM_heightstart = tilesets_start[atoi((*tiles).GetString("General", "HeightBase"))]; // now draw everything int u, v, z; @@ -5911,9 +5905,10 @@ void CIsoView::DrawMap() { if (!pic.bTried) { - if (auto const pOverlayId = rules.sections["OverlayTypes"].GetValue(m.overlay)) { + auto const& overlayId = rules.GetSection("OverlayTypes").Nth(m.overlay).second; + if (!overlayId.IsEmpty()) { SetError("Loading graphics"); - theApp.m_loading->LoadOverlayGraphic(*pOverlayId, m.overlay); + theApp.m_loading->LoadOverlayGraphic(overlayId, m.overlay); UpdateOverlayPictures(m.overlay); if (ovrlpics[m.overlay][m.overlaydata] != NULL) { pic = *ovrlpics[m.overlay][m.overlaydata]; @@ -6040,7 +6035,7 @@ void CIsoView::DrawMap() { SetError("Loading graphics"); theApp.m_loading->LoadUnitGraphic(objp.type); - ::Map->UpdateBuildingInfo(objp.type); + ::Map->UpdateBuildingInfo(&objp.type); int dir = (7 - objp.direction / 32) % 8; pic = buildinginfo[id].pic[dir]; if (pic.pic == NULL) pic = buildinginfo[id].pic[0]; @@ -6080,7 +6075,7 @@ void CIsoView::DrawMap() { SetError("Loading graphics"); theApp.m_loading->LoadUnitGraphic(upg); - ::Map->UpdateBuildingInfo(upg); + ::Map->UpdateBuildingInfo(&upg); pic = pics[GetUnitPictureFilename(upg, dir)]; if (pic.pic == NULL) missingimages[upg] = TRUE; } @@ -6089,8 +6084,8 @@ void CIsoView::DrawMap() { static const CString LocLookup[3][2] = { {"PowerUp1LocXX", "PowerUp1LocYY"}, {"PowerUp2LocXX", "PowerUp2LocYY"}, {"PowerUp3LocXX", "PowerUp3LocYY"} }; const auto drawCoordsPowerUp = drawCoordsBldShp + ProjectedVec( - atoi(art.sections[objp.type].values[LocLookup[upgrade][0]]), - atoi(art.sections[objp.type].values[LocLookup[upgrade][1]]) + atoi(art.GetString(objp.type, LocLookup[upgrade][0])), + atoi(art.GetString(objp.type, LocLookup[upgrade][1])) ); // py-=atoi(art.sections[obj.type].values["PowerUp1LocZZ"]); #ifndef NOSURFACES @@ -6150,19 +6145,18 @@ void CIsoView::DrawMap() if (pic.pic == NULL) { - if (!missingimages[*rules.sections["BuildingTypes"].GetValue(m.node.type)]) - { + auto const& buildingId = rules.GetSection("BuildingTypes").Nth(m.node.type).second; + if (!buildingId.IsEmpty() && !missingimages[buildingId]) { SetError("Loading graphics"); - theApp.m_loading->LoadUnitGraphic(*rules.sections["BuildingTypes"].GetValue(m.node.type)); - ::Map->UpdateBuildingInfo(*rules.sections["BuildingTypes"].GetValue(m.node.type)); + theApp.m_loading->LoadUnitGraphic(buildingId); + ::Map->UpdateBuildingInfo(&buildingId); pic = buildinginfo[id].pic[0]; } - if (pic.pic == NULL); - { + if (pic.pic == NULL) { #ifndef NOSURFACES Blit(pics["HOUSE"].pic, drawCoordsBld.x, drawCoordsBld.y - 19); #endif - missingimages[*rules.sections["BuildingTypes"].GetValue(m.node.type)] = TRUE; + missingimages[buildingId] = TRUE; } } @@ -6374,7 +6368,7 @@ void CIsoView::DrawMap() { SetError("Loading graphics"); theApp.m_loading->LoadUnitGraphic(type); - ::Map->UpdateTreeInfo(type); + ::Map->UpdateTreeInfo(&type); pic = treeinfo[id].pic; } if (pic.pic == NULL) diff --git a/MissionEditor/IsoView.h b/MissionEditor/IsoView.h index 41b3e8d..0a56abb 100644 --- a/MissionEditor/IsoView.h +++ b/MissionEditor/IsoView.h @@ -137,7 +137,7 @@ protected: afx_msg void OnDeadChar(UINT nChar, UINT nRepCnt, UINT nFlags); afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags); afx_msg void OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags); - afx_msg void OnTimer(UINT nIDEvent); + afx_msg void OnTimer(UINT_PTR nIDEvent); afx_msg void OnRButtonDown(UINT nFlags, CPoint point); afx_msg void OnKillFocus(CWnd* pNewWnd); //}}AFX_MSG diff --git a/MissionEditor/Lighting.cpp b/MissionEditor/Lighting.cpp index 5470b06..8d7f7e5 100644 --- a/MissionEditor/Lighting.cpp +++ b/MissionEditor/Lighting.cpp @@ -89,17 +89,17 @@ void CLighting::UpdateDialog() { CIniFile& ini=Map->GetIniFile(); - m_Ambient.SetWindowText(ini.sections["Lighting"].values["Ambient"]); - m_Ambient2.SetWindowText(ini.sections["Lighting"].values["IonAmbient"]); - m_Level.SetWindowText(ini.sections["Lighting"].values["Level"]); - m_Level2.SetWindowText(ini.sections["Lighting"].values["IonLevel"]); - m_Red.SetWindowText(ini.sections["Lighting"].values["Red"]); - m_Red2.SetWindowText(ini.sections["Lighting"].values["IonRed"]); - m_Green.SetWindowText(ini.sections["Lighting"].values["Green"]); - m_Green2.SetWindowText(ini.sections["Lighting"].values["IonGreen"]); - m_Blue.SetWindowText(ini.sections["Lighting"].values["Blue"]); - m_Blue2.SetWindowText(ini.sections["Lighting"].values["IonBlue"]); - //MessageBox(ini.sections["Lightning"].values["Ambient"]); + m_Ambient.SetWindowText(ini.GetString("Lighting", "Ambient")); + m_Ambient2.SetWindowText(ini.GetString("Lighting", "IonAmbient")); + m_Level.SetWindowText(ini.GetString("Lighting", "Level")); + m_Level2.SetWindowText(ini.GetString("Lighting", "IonLevel")); + m_Red.SetWindowText(ini.GetString("Lighting", "Red")); + m_Red2.SetWindowText(ini.GetString("Lighting", "IonRed")); + m_Green.SetWindowText(ini.GetString("Lighting", "Green")); + m_Green2.SetWindowText(ini.GetString("Lighting", "IonGreen")); + m_Blue.SetWindowText(ini.GetString("Lighting", "Blue")); + m_Blue2.SetWindowText(ini.GetString("Lighting", "IonBlue")); + //MessageBox(ini.GetString("Lightning", "Ambient")); } BOOL CLighting::OnInitDialog() @@ -125,8 +125,7 @@ void CLighting::OnChangeAmbient() CString ctext; m_Ambient.GetWindowText(ctext); CString text=(char*)(LPCTSTR)ctext; - ini.sections["Lighting"].values["Ambient"]=text; - + ini.SetString("Lighting", "Ambient", text); } void CLighting::OnChangeLevel() @@ -136,8 +135,7 @@ void CLighting::OnChangeLevel() CString ctext; m_Level.GetWindowText(ctext); CString text=(char*)(LPCTSTR)ctext; - ini.sections["Lighting"].values["Level"]=text; - + ini.SetString("Lighting", "Level", text); } void CLighting::OnKillfocusAmbient() @@ -152,7 +150,7 @@ void CLighting::OnChangeRed() CString ctext; m_Red.GetWindowText(ctext); CString text=(char*)(LPCTSTR)ctext; - ini.sections["Lighting"].values["Red"]=text; + ini.SetString("Lighting", "Red", text); } void CLighting::OnChangeGreen() @@ -162,7 +160,7 @@ void CLighting::OnChangeGreen() CString ctext; m_Green.GetWindowText(ctext); CString text=(char*)(LPCTSTR)ctext; - ini.sections["Lighting"].values["Green"]=text; + ini.SetString("Lighting", "Green", text); } void CLighting::OnChangeBlue() @@ -172,7 +170,7 @@ void CLighting::OnChangeBlue() CString ctext; m_Blue.GetWindowText(ctext); CString text=(char*)(LPCTSTR)ctext; - ini.sections["Lighting"].values["Blue"]=text; + ini.SetString("Lighting", "Blue", text); } void CLighting::OnChangeAmbient2() @@ -182,7 +180,7 @@ void CLighting::OnChangeAmbient2() CString ctext; m_Ambient2.GetWindowText(ctext); CString text=(char*)(LPCTSTR)ctext; - ini.sections["Lighting"].values["IonAmbient"]=text; + ini.SetString("Lighting", "IonAmbient", text); } void CLighting::OnChangeLevel2() @@ -192,7 +190,7 @@ void CLighting::OnChangeLevel2() CString ctext; m_Level2.GetWindowText(ctext); CString text=(char*)(LPCTSTR)ctext; - ini.sections["Lighting"].values["IonLevel"]=text; + ini.SetString("Lighting", "IonLevel", text); } void CLighting::OnChangeRed2() @@ -202,7 +200,7 @@ void CLighting::OnChangeRed2() CString ctext; m_Red2.GetWindowText(ctext); CString text=(char*)(LPCTSTR)ctext; - ini.sections["Lighting"].values["IonRed"]=text; + ini.SetString("Lighting", "IonRed", text); } void CLighting::OnChangeGreen2() @@ -212,7 +210,7 @@ void CLighting::OnChangeGreen2() CString ctext; m_Green2.GetWindowText(ctext); CString text=(char*)(LPCTSTR)ctext; - ini.sections["Lighting"].values["IonGreen"]=text; + ini.SetString("Lighting", "IonGreen", text); } void CLighting::OnChangeBlue2() @@ -222,5 +220,5 @@ void CLighting::OnChangeBlue2() CString ctext; m_Blue2.GetWindowText(ctext); CString text=(char*)(LPCTSTR)ctext; - ini.sections["Lighting"].values["IonBlue"]=text; + ini.SetString("Lighting", "IonBlue", text); } diff --git a/MissionEditor/Loading.cpp b/MissionEditor/Loading.cpp index f41bd9b..02e8a7d 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,31 @@ 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"]; + _rules_image = lpUnittype; + _rules_image = rules.GetStringOr(lpUnittype, "Image", _rules_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"]; + 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 +1343,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 +1405,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 +1414,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 +1432,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 +1475,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 +1571,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 +1605,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 +1629,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 +1671,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 +1723,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 +1736,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 +1749,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 +1761,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 +1773,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 +1786,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 +1799,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 +1812,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 +1825,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 +1838,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 +1850,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 +1863,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 +1878,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 +1888,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 +1923,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 +1935,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 +1964,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 +1990,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 +2000,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 +2032,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 +2136,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 +2177,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 +2211,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 +2223,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 +2231,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 +2258,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 +2266,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 +2279,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 +2307,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 +2355,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 +2378,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 +3182,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 +3234,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 +3325,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 +3384,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 +3395,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 +3572,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 +3615,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 +3622,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 +3680,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 +3695,52 @@ 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"]; + image = rules.GetStringOr(lpOvrlName, "Image", lpOvrlName); 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 +3920,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 +4293,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 +4797,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 +5039,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 +5067,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 +5081,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 +5145,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; @@ -6546,23 +5163,20 @@ 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"]; + _rules_image = rules.GetStringOr(lpUnittype, "Image", lpUnittype); 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 +5396,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 +5550,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 diff --git a/MissionEditor/MMXSavingOptionsDlg.cpp b/MissionEditor/MMXSavingOptionsDlg.cpp index 80af27f..c81cf39 100644 --- a/MissionEditor/MMXSavingOptionsDlg.cpp +++ b/MissionEditor/MMXSavingOptionsDlg.cpp @@ -53,7 +53,7 @@ CMMXSavingOptionsDlg::CMMXSavingOptionsDlg(CWnd* pParent /*=NULL*/) m_Standard = TRUE; //}}AFX_DATA_INIT - m_Description=Map->GetIniFile().sections["Basic"].values["Name"]; + m_Description = Map->GetIniFile().GetString("Basic", "Name"); } diff --git a/MissionEditor/MapD.cpp b/MissionEditor/MapD.cpp index 238fa46..daa575d 100644 --- a/MissionEditor/MapD.cpp +++ b/MissionEditor/MapD.cpp @@ -82,9 +82,9 @@ void CMapD::UpdateDialog() { CIniFile& ini=Map->GetIniFile(); - m_LocalSize.SetWindowText( ini.sections["Map"].values["LocalSize"] ); + m_LocalSize.SetWindowText(ini.GetString("Map", "LocalSize")); //m_Size.SetWindowText( ini.sections["Map"].values["Size"] ); - m_Theater.SetWindowText( ini.sections["Map"].values["Theater"] ); + m_Theater.SetWindowText(ini.GetString("Map", "Theater")); char c[50]; itoa(Map->GetWidth(), c, 10); @@ -108,7 +108,7 @@ void CMapD::OnChangeUsesize() void CMapD::OnEditchangeTheater() { CIniFile& ini=Map->GetIniFile(); - ini.sections["Map"].values["Theater"]=GetText(&m_Theater); + ini.SetString("Map", "Theater", GetText(&m_Theater)); } void CMapD::UpdateStrings() @@ -125,7 +125,7 @@ void CMapD::UpdateStrings() void CMapD::OnChangelocal() { CIniFile& ini=Map->GetIniFile(); - ini.sections["Map"].values["LocalSize"]=GetText(&m_LocalSize); + ini.SetString("Map", "LocalSize", GetText(&m_LocalSize)); Map->CalcMapRect(); ((CFinalSunDlg*)theApp.m_pMainWnd)->m_view.m_isoview->RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW); diff --git a/MissionEditor/MapData.cpp b/MissionEditor/MapData.cpp index 1faee3e..da1c130 100644 --- a/MissionEditor/MapData.cpp +++ b/MissionEditor/MapData.cpp @@ -57,21 +57,24 @@ void DoEvents() void GetNodeName(CString& name, int n); -CString GetFree(const char* section) +CString GetFree(const char* sectionName) { - CIniFile& ini = Map->GetIniFile(); + auto const ini = Map->GetIniFile(); - int i = 0; - char l[50]; - itoa(i, l, 10); + int idx = 0; + char idStr[50]; + itoa(idx, idStr, 10); - while (ini.sections[section].values.find(l) != ini.sections[section].values.end()) - { - i++; - itoa(i, l, 10); + auto const& section = ini.GetSection(sectionName); + for (;;) { + itoa(idx, idStr, 10); + if (!section.Exists(idStr)) { + break; + } + idx++; } - return l; + return idStr; } @@ -80,65 +83,37 @@ This function calculates a number for the specified building type. Because this function is slow, you should only use it to fill the buildingid map */ -inline int GetBuildingNumber(LPCTSTR name) -{ - CIniFile& ini = Map->GetIniFile(); - int v = rules.sections["BuildingTypes"].FindValue(name); +int getItemNumber(const CString& section, const CString& name) { + auto const& ini = Map->GetIniFile(); + int idx = rules.GetSection(section).FindValue(name); - if (v > -1) - { - - return v; + if (idx >= 0) { + return idx; } - v = ini.sections["BuildingTypes"].FindValue(name); - if (v > -1) - { - return v + 0x0C00; + idx = ini.GetSection(section).FindValue(name); + if (idx > -1) { + // why ? + return idx + 0x0C00; } return -1; } -inline int GetTerrainNumber(LPCTSTR name) +inline int GetBuildingNumber(const CString& name) { - CIniFile& ini = Map->GetIniFile(); + return getItemNumber("BuildingTypes", name); +} - int v = rules.sections["TerrainTypes"].FindValue(name); - - if (v > -1) - { - - return v; - } - - v = ini.sections["TerrainTypes"].FindValue(name); - if (v > -1) - { - return v + 0x0C00; - } - return -1; +inline int GetTerrainNumber(const CString& name) +{ + return getItemNumber("TerrainTypes", name); } #ifdef SMUDGE_SUPP -inline int GetSmudgeNumber(LPCTSTR name) +inline int GetSmudgeNumber(const CString& name) { - CIniFile& ini = Map->GetIniFile(); - - int v = rules.sections["SmudgeTypes"].FindValue(name); - - if (v > -1) - { - - return v; - } - - v = ini.sections["SmudgeTypes"].FindValue(name); - if (v > -1) - { - return v + 0x0C00; - } - return -1; + return getItemNumber("SmudgeTypes", name); } #endif @@ -266,9 +241,9 @@ CMapData::~CMapData() void CMapData::CalcMapRect() { - CIniFileSection& sec = m_mapfile.sections["Map"]; + auto const& sec = m_mapfile.GetSection("Map"); char msize[50]; - strcpy_s(msize, sec.values["Size"]); + strcpy_s(msize, sec.GetString("Size")); int cupos = 0; @@ -303,7 +278,9 @@ void CMapData::CalcMapRect() m_maprect.right = atoi(custr); cucomma = strchr(&msize[cupos], ','); // we check again... could be there is a new ini format - if (cucomma == NULL) cucomma = (char*)((int)msize + strlen(msize)); + if (cucomma == NULL) { + cucomma = msize + strlen(msize); + } memcpy_s(custr, custr_size, &msize[cupos], (cucomma - msize) - cupos + 1); custr[((cucomma - msize)) - cupos] = 0; cupos = cucomma - msize + 1; @@ -314,7 +291,7 @@ void CMapData::CalcMapRect() // local size - strcpy_s(msize, sec.values["LocalSize"]); + strcpy_s(msize, sec.GetString("LocalSize")); cupos = 0; @@ -346,7 +323,9 @@ void CMapData::CalcMapRect() cucomma = strchr(&msize[cupos], ','); // we check again... could be there is a new ini format - if (cucomma == NULL) cucomma = (char*)((int)msize + strlen(msize)); + if (cucomma == NULL) { + cucomma = msize + strlen(msize); + } memcpy_s(custr, custr_size, &msize[cupos], (cucomma - msize) - cupos + 1); custr[((cucomma - msize)) - cupos] = 0; cupos = cucomma - msize + 1; @@ -366,52 +345,47 @@ WORD CMapData::GetHousesCount(BOOL bCountries) bCountries = FALSE; #endif - CString sSection = MAPHOUSES; - if (bCountries) sSection = HOUSES; + CString sSection = bCountries ? HOUSES : MAPHOUSES; - if (m_mapfile.sections.find(sSection) != m_mapfile.sections.end()) - if (m_mapfile.sections[sSection].values.size() > 0) return m_mapfile.sections[sSection].values.size(); + if (auto const count = m_mapfile.GetSection(sSection).Size()) { + return count; + } - return(rules.sections[HOUSES].values.size()); + return(rules.GetSection(HOUSES).Size()); } CString CMapData::GetHouseID(WORD wHouse, BOOL bCountry) { - if (wHouse >= GetHousesCount()) - return CString(""); + if (wHouse >= GetHousesCount()) { + return ""; + } #ifndef RA2_MODE bCountry = FALSE; #endif - - CString sSection = MAPHOUSES; - if (bCountry) sSection = HOUSES; - - - if (m_mapfile.sections.find(sSection) != m_mapfile.sections.end()) - if (m_mapfile.sections[sSection].values.size() > 0) return *m_mapfile.sections[sSection].GetValue(wHouse); - - return(*rules.sections[HOUSES].GetValue(wHouse)); + CString sSection = bCountry ? HOUSES : MAPHOUSES; + auto const& houseSec = m_mapfile.GetSection(sSection); + if (wHouse < houseSec.Size()) { + return houseSec.Nth(wHouse).second; + } + return rules.GetSection(HOUSES).Nth(wHouse).second; } DWORD CMapData::GetAITriggerTypeCount() { - if (m_mapfile.sections.find("AITriggerTypes") != m_mapfile.sections.end()) - return(m_mapfile.sections["AITriggerTypes"].values.size()); - - return 0; + return m_mapfile.GetSection("AITriggerTypes").Size(); } void CMapData::GetAITriggerType(DWORD dwAITriggerType, AITRIGGERTYPE* pAITrg) { - CString data; - - if (dwAITriggerType >= GetAITriggerTypeCount()) + if (dwAITriggerType >= GetAITriggerTypeCount()) { return; + } - data = *m_mapfile.sections["AITriggerTypes"].GetValue(dwAITriggerType); + auto const& aiTriggerTypeSec = m_mapfile.GetSection("AITriggerTypes"); + auto const& [id, data] = aiTriggerTypeSec.Nth(dwAITriggerType); - pAITrg->ID = *m_mapfile.sections["AITriggerTypes"].GetValueName(dwAITriggerType); + pAITrg->ID = id; pAITrg->name = GetParam(data, 0); pAITrg->teamtype1 = GetParam(data, 1); pAITrg->owner = GetParam(data, 2); @@ -430,32 +404,31 @@ void CMapData::GetAITriggerType(DWORD dwAITriggerType, AITRIGGERTYPE* pAITrg) pAITrg->easy = GetParam(data, 15); pAITrg->medium = GetParam(data, 16); pAITrg->hard = GetParam(data, 17); - - } WORD CMapData::GetHouseIndex(LPCTSTR lpHouse) { - if (m_mapfile.sections.find(HOUSES) != m_mapfile.sections.end()) - if (m_mapfile.sections[HOUSES].values.size() > 0) - return m_mapfile.sections[HOUSES].FindValue(lpHouse); - - - return rules.sections[HOUSES].FindValue(lpHouse); + auto const idx = m_mapfile.GetSection(HOUSES).FindValue(lpHouse); + if (idx >= 0) { + return idx; + } + return rules.GetSection(HOUSES).FindValue(lpHouse); } DWORD CMapData::GetAITriggerTypeIndex(LPCTSTR lpID) { - if (GetAITriggerTypeCount() == 0) return 0; + if (GetAITriggerTypeCount() == 0) { + return 0; + } - return m_mapfile.sections["AITriggerTypes"].FindName(lpID); + return m_mapfile.GetSection("AITriggerTypes").FindIndex(lpID); } CString CMapData::GetAITriggerTypeID(DWORD dwAITriggerType) { if (dwAITriggerType >= GetAITriggerTypeCount()) return CString(""); - return *m_mapfile.sections["AITriggerTypes"].GetValueName(dwAITriggerType); + return m_mapfile["AITriggerTypes"].Nth(dwAITriggerType).first; } CIniFile& CMapData::GetIniFile() @@ -490,21 +463,20 @@ void CMapData::UpdateIniFile(DWORD dwFlags) CalcMapRect(); InitMinimap(); - slopesetpiecesset = atoi((*tiles).sections["General"].values["SlopeSetPieces"]); - rampset = atoi((*tiles).sections["General"].values["RampBase"]); - rampsmoothset = atoi((*tiles).sections["General"].values["RampSmooth"]); - cliffset = atoi((*tiles).sections["General"].values["CliffSet"]); + slopesetpiecesset = tiles->GetInteger("General", "SlopeSetPieces"); + rampsmoothset = tiles->GetInteger("General", "RampSmooth"); + cliffset = tiles->GetInteger("General", "CliffSet"); cliffset_start = GetTileID(cliffset, 0); - waterset = atoi((*tiles).sections["General"].values["WaterSet"]); - shoreset = atoi((*tiles).sections["General"].values["ShorePieces"]); - rampset_start = GetTileID(atoi((*tiles).sections["General"].values["RampBase"]), 0); - ramp2set = atoi(g_data.sections["NewUrbanInfo"].values["Ramps2"]); + waterset = tiles->GetInteger("General", "WaterSet"); + shoreset = tiles->GetInteger("General", "ShorePieces"); + rampset_start = GetTileID(tiles->GetInteger("General", "RampBase"), 0); + ramp2set = g_data.GetInteger("NewUrbanInfo", "Ramps2"); ramp2set_start = GetTileID(ramp2set, 0); - pave2set = atoi(g_data.sections["NewUrbanInfo"].values["Morphable2"]); + pave2set = g_data.GetInteger("NewUrbanInfo", "Morphable2"); pave2set_start = GetTileID(pave2set, 0); - cliff2set = atoi(g_data.sections["NewUrbanInfo"].values["Cliffs2"]); + cliff2set = g_data.GetInteger("NewUrbanInfo", "Cliffs2"); cliff2set_start = GetTileID(cliff2set, 0); - cliffwater2set = atoi(g_data.sections["NewUrbanInfo"].values["CliffsWater2"]); + cliffwater2set = g_data.GetInteger("NewUrbanInfo", "CliffsWater2"); InitializeUnitTypes(); UpdateBuildingInfo(); @@ -606,10 +578,11 @@ void CMapData::LoadMap(const std::string& file) char lowc[MAX_PATH] = { 0 }; strcpy_s(lowc, file.c_str()); _strlwr(lowc); - if (strstr(lowc, ".mpr")) - { - m_mapfile.sections["Basic"].values["MultiplayerOnly"] = "1"; - if (m_mapfile.sections["Basic"].FindName("Player") >= 0) m_mapfile.sections["Basic"].values.erase("Player"); + if (strstr(lowc, ".mpr")) { + m_mapfile.SetString("Basic", "MultiplayerOnly", "1"); + if (m_mapfile["Basic"].HasValue("Player")) { + m_mapfile.TryGetSection("Basic")->RemoveValue("Player"); + } } @@ -618,25 +591,19 @@ void CMapData::LoadMap(const std::string& file) errstream.flush(); // repair taskforces (bug in earlier 0.95 versions) - for (i = 0;i < m_mapfile.sections["TaskForces"].values.size();i++) - { + for (auto const& [idx, id] : m_mapfile.GetSection("TaskForces")) { vector toDelete; toDelete.reserve(5); - CIniFileSection& sec = m_mapfile.sections[*m_mapfile.sections["TaskForces"].GetValue(i)]; - int e; - for (e = 0;e < sec.values.size();e++) - { - if (sec.GetValue(e)->GetLength() == 0) - { - toDelete.push_back(*sec.GetValueName(e)); + auto const sec = m_mapfile.TryGetSection(id); + ASSERT(sec != nullptr); + for (auto const& [key, val] : *sec) { + if (val.IsEmpty()) { + toDelete.push_back(key); } - - } - for (e = 0;e < toDelete.size();e++) - { - sec.values.erase(toDelete[e]); + for (auto const& keyToDelete : toDelete) { + sec->RemoveByKey(keyToDelete); } } @@ -702,9 +669,8 @@ void CMapData::LoadMap(const std::string& file) UpdateTreeInfo(); ((CFinalSunDlg*)theApp.m_pMainWnd)->m_view.m_isoview->UpdateOverlayPictures(); - - if (m_mapfile.sections["Map"].values["Theater"] == THEATER0) - { + auto const& theaterType = m_mapfile.GetString("Map", "Theater"); + if (theaterType == THEATER0) { tiledata = &s_tiledata; tiledata_count = &s_tiledata_count; tiles = &tiles_s; @@ -736,8 +702,7 @@ void CMapData::LoadMap(const std::string& file) theApp.m_loading->cur_theat = 'T'; } - else if (m_mapfile.sections["Map"].values["Theater"] == THEATER1) - { + else if (theaterType == THEATER1) { tiledata = &t_tiledata; tiledata_count = &t_tiledata_count; tiles = &tiles_t; @@ -767,9 +732,7 @@ void CMapData::LoadMap(const std::string& file) theApp.m_loading->FreeTileSet(); theApp.m_loading->InitTMPs(&dlg.m_Progress); theApp.m_loading->cur_theat = 'A'; - } - else if (m_mapfile.sections["Map"].values["Theater"] == THEATER2) - { + } else if (theaterType == THEATER2) { tiledata = &t_tiledata; tiledata_count = &t_tiledata_count; tiles = &tiles_t; @@ -799,9 +762,7 @@ void CMapData::LoadMap(const std::string& file) theApp.m_loading->FreeTileSet(); theApp.m_loading->InitTMPs(&dlg.m_Progress); theApp.m_loading->cur_theat = 'U'; - } - else if (yuri_mode && m_mapfile.sections["Map"].values["Theater"] == THEATER3) - { + } else if (yuri_mode && theaterType == THEATER3) { tiledata = &t_tiledata; tiledata_count = &t_tiledata_count; tiles = &tiles_t; @@ -834,9 +795,7 @@ void CMapData::LoadMap(const std::string& file) theApp.m_loading->InitTMPs(&dlg.m_Progress); theApp.m_loading->cur_theat = 'N'; - } - else if (yuri_mode && m_mapfile.sections["Map"].values["Theater"] == THEATER4) - { + } else if (yuri_mode && theaterType == THEATER4) { tiledata = &t_tiledata; tiledata_count = &t_tiledata_count; tiles = &tiles_t; @@ -869,9 +828,7 @@ void CMapData::LoadMap(const std::string& file) theApp.m_loading->InitTMPs(&dlg.m_Progress); theApp.m_loading->cur_theat = 'L'; - } - else if (m_mapfile.sections["Map"].values["Theater"] == THEATER5) - { + } else if (theaterType == THEATER5) { tiledata = &t_tiledata; tiledata_count = &t_tiledata_count; tiles = &tiles_t; @@ -905,9 +862,7 @@ void CMapData::LoadMap(const std::string& file) theApp.m_loading->InitTMPs(&dlg.m_Progress); theApp.m_loading->cur_theat = 'D'; - } - else - { + } else { theApp.m_loading->FreeAll(); CString s = "Fatal error! %9 doesn´t support the theater of this map!"; s = TranslateStringACP(s); @@ -957,12 +912,8 @@ void CMapData::Unpack() CString ovrl; int i; - - ovrl = ""; - - for (i = 0;i < m_mapfile.sections["OverlayPack"].values.size();i++) - { - ovrl += *m_mapfile.sections["OverlayPack"].GetValue(i); + for (auto const& [idx, val] : m_mapfile.GetSection("OverlayPack")) { + ovrl += val; } //BYTE values[262144]; @@ -982,10 +933,9 @@ void CMapData::Unpack() memcpy(m_Overlay, values.data(), std::min(VALUESIZE, values.size())); ovrl = ""; - - for (i = 0;i < m_mapfile.sections["OverlayDataPack"].values.size();i++) - { - ovrl += *m_mapfile.sections["OverlayDataPack"].GetValue(i); + + for (auto const& [idx, val] : m_mapfile.GetSection("OverlayDataPack")) { + ovrl += val; } values.assign(VALUESIZE, 0); @@ -1004,29 +954,26 @@ void CMapData::Unpack() CString IsoMapPck; int len_needed = 0; - CIniFileSection& sec = m_mapfile.sections["IsoMapPack5"]; - int lines = sec.values.size(); - + auto const& sec = m_mapfile["IsoMapPack5"]; /*char c[50]; itoa(m_mapfile.sections["IsoMapPack5"].values.size(), c, 10); MessageBox(0,c,"",0);*/ - for (i = 0;i < lines;i++) - { - len_needed += sec.GetValue(i)->GetLength(); + for (auto const& [key, val] : sec) { + len_needed += val.GetLength(); } LPSTR lpMapPack = new(char[len_needed + 1]); memset(lpMapPack, 0, len_needed + 1); int cur_pos = 0; - for (i = 0;i < lines;i++) + for (auto const& [key, val] : sec) { - memcpy(lpMapPack + cur_pos, (LPCSTR)*sec.GetValue(i), sec.GetValue(i)->GetLength()); - cur_pos += sec.GetValue(i)->GetLength(); + memcpy(lpMapPack + cur_pos, val, val.GetLength()); + cur_pos += val.GetLength(); DoEvents(); - //IsoMapPck+=*sec.GetValue(i); + //IsoMapPck+=val; } IsoMapPck = lpMapPack; @@ -1100,17 +1047,16 @@ void CMapData::Pack(BOOL bCreatePreview, BOOL bCompression) int i; BYTE* base64 = NULL; // must be freed! - m_mapfile.sections.erase("OverlayPack"); - m_mapfile.sections.erase("OverlayDataPack"); - m_mapfile.sections.erase("IsoMapPack5"); // only activate when packing isomappack is supported + m_mapfile.DeleteSection("OverlayPack"); + m_mapfile.DeleteSection("OverlayDataPack"); + m_mapfile.DeleteSection("IsoMapPack5"); // only activate when packing isomappack is supported DWORD pos; errstream << "Creating Digest" << endl; errstream.flush(); - if (m_mapfile.sections["Digest"].values.size() == 0) - { + if (m_mapfile["Digest"].Size() == 0) { srand(GetTickCount()); unsigned short vals[10]; for (i = 0;i < 10;i++) @@ -1128,11 +1074,16 @@ void CMapData::Pack(BOOL bCreatePreview, BOOL bCompression) char str[200]; memset(str, 0, 200); WORD cpysize = 70; - if (pos + cpysize > strlen((char*)base64)) cpysize = strlen((char*)base64) - pos; + if (pos + cpysize > strlen((char*)base64)) { + cpysize = strlen((char*)base64) - pos; + } memcpy(str, &base64[pos], cpysize); - if (strlen(str) > 0) - m_mapfile.sections["Digest"].values[cLine] = str; - if (cpysize < 70) break; + if (strlen(str) > 0) { + m_mapfile.SetString("Digest", cLine, str); + } + if (cpysize < 70) { + break; + } pos += 70; } @@ -1145,7 +1096,7 @@ void CMapData::Pack(BOOL bCreatePreview, BOOL bCompression) BYTE* hexpacked = NULL; // must be freed! - errstream << "Values allocated. Pointer: " << (int)values << endl; + errstream << "Values allocated. Pointer: " << std::hex << values << endl; errstream.flush(); @@ -1173,11 +1124,16 @@ void CMapData::Pack(BOOL bCreatePreview, BOOL bCompression) char str[200]; memset(str, 0, 200); WORD cpysize = 70; - if (pos + cpysize > strlen((char*)base64)) cpysize = strlen((char*)base64) - pos; + if (pos + cpysize > strlen((char*)base64)) { + cpysize = strlen((char*)base64) - pos; + } memcpy(str, &base64[pos], cpysize); - if (strlen(str) > 0) - m_mapfile.sections["OverlayPack"].values[cLine] = str; - if (cpysize < 70) break; + if (strlen(str) > 0) { + m_mapfile.SetString("OverlayPack", cLine, str); + } + if (cpysize < 70) { + break; + } pos += 70; } @@ -1223,11 +1179,16 @@ void CMapData::Pack(BOOL bCreatePreview, BOOL bCompression) char str[200]; memset(str, 0, 200); WORD cpysize = 70; - if (pos + cpysize > strlen((char*)base64)) cpysize = strlen((char*)base64) - pos; + if (pos + cpysize > strlen((char*)base64)) { + cpysize = strlen((char*)base64) - pos; + } memcpy(str, &base64[pos], cpysize); - if (strlen(str) > 0) - m_mapfile.sections["OverlayDataPack"].values[cLine] = str; - if (cpysize < 70) break; + if (strlen(str) > 0) { + m_mapfile.SetString("OverlayDataPack", cLine, str); + } + if (cpysize < 70) { + break; + } pos += 70; } @@ -1269,10 +1230,13 @@ void CMapData::Pack(BOOL bCreatePreview, BOOL bCompression) int cpysize = 70; if (pos + cpysize > base64len) cpysize = base64len - pos; memcpy(str, &base64[pos], cpysize); - if (cpysize) - m_mapfile.sections["IsoMapPack5"].values[cLine] = str; + if (cpysize) { + m_mapfile.SetString("IsoMapPack5", cLine, str); + } - if (cpysize < 70) break; + if (cpysize < 70) { + break; + } pos += 70; } @@ -1294,13 +1258,13 @@ void CMapData::Pack(BOOL bCreatePreview, BOOL bCompression) int pitch; ((CFinalSunDlg*)theApp.m_pMainWnd)->m_view.m_minimap.DrawMinimap(&lpDibData, biinfo, pitch); - m_mapfile.sections.erase("PreviewPack"); - m_mapfile.sections["Preview"].values["Size"] = m_mapfile.sections["Map"].values["Size"]; + m_mapfile.DeleteSection("PreviewPack"); + m_mapfile.SetString("Preview", "Size", m_mapfile.GetString("Map","Size")); char c[50]; itoa(biinfo.bmiHeader.biWidth, c, 10); - m_mapfile.sections["Preview"].values["Size"] = SetParam(m_mapfile.sections["Preview"].values["Size"], 2, c); + m_mapfile.SetString("Preview", "Size", SetParam(m_mapfile.GetString("Preview", "Size"), 2, c)); itoa(biinfo.bmiHeader.biHeight, c, 10); - m_mapfile.sections["Preview"].values["Size"] = SetParam(m_mapfile.sections["Preview"].values["Size"], 3, c); + m_mapfile.SetString("Preview", "Size", SetParam(m_mapfile.GetString("Preview", "Size"), 3, c)); BYTE* lpRAW = new(BYTE[biinfo.bmiHeader.biWidth * biinfo.bmiHeader.biHeight * 3]); @@ -1342,9 +1306,12 @@ void CMapData::Pack(BOOL bCreatePreview, BOOL bCompression) WORD cpysize = 70; if (pos + cpysize > strlen((char*)base64)) cpysize = strlen((char*)base64) - pos; memcpy(str, &base64[pos], cpysize); - if (strlen(str) > 0) - m_mapfile.sections["PreviewPack"].values[cLine] = str; - if (cpysize < 70) break; + if (strlen(str) > 0) { + m_mapfile.SetString("PreviewPack", cLine, str); + } + if (cpysize < 70) { + break; + } pos += 70; } @@ -1501,8 +1468,7 @@ void CMapData::UpdateInfantry(BOOL bSave) { vector& iv = m_infantry; - if (bSave == FALSE) - { + if (bSave == FALSE) { iv.clear(); iv.reserve(100); @@ -1514,181 +1480,155 @@ void CMapData::UpdateInfantry(BOOL bSave) fielddata[i].infantry[e] = -1; } + for (auto const& [id, data] : m_mapfile.GetSection("Infantry")) { + int x = atoi(GetParam(data, 4)); + int y = atoi(GetParam(data, 3)); + int sp = atoi(GetParam(data, 5)); + int pos = x + y * GetIsoSize(); - if (m_mapfile.sections.find("Infantry") != m_mapfile.sections.end()) - { - CIniFileSection& sec = m_mapfile.sections["Infantry"]; + INFANTRY 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.flag2 = GetParam(data, 10); + id.flag3 = GetParam(data, 11); + id.flag4 = GetParam(data, 12); + id.flag5 = GetParam(data, 13); - for (i = 0;i < sec.values.size();i++) + iv.push_back(id); + + int spp = sp - 1; + if (spp < 0) spp = 0; + + if (spp < SUBPOS_COUNT) + if (pos < fielddata_size) + fielddata[pos].infantry[spp] = iv.size() - 1; + + Mini_UpdatePos(x, y, IsMultiplayer()); + + + + /*else { - CString data = *sec.GetValue(i); - - int x = atoi(GetParam(data, 4)); - int y = atoi(GetParam(data, 3)); - int sp = atoi(GetParam(data, 5)); - int pos = x + y * GetIsoSize(); - - INFANTRY 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.flag2 = GetParam(data, 10); - id.flag3 = GetParam(data, 11); - id.flag4 = GetParam(data, 12); - id.flag5 = GetParam(data, 13); - - iv.push_back(id); - - int spp = sp - 1; - if (spp < 0) spp = 0; - - if (spp < SUBPOS_COUNT) - if (pos < fielddata_size) - fielddata[pos].infantry[spp] = iv.size() - 1; - - Mini_UpdatePos(x, y, IsMultiplayer()); - - - - /*else + int e; + for(e=0;em_view.m_isoview->GetColor(GetParam(val, 0)); + sp.strength = atoi(GetParam(val, 2)); + sp.upgrade1 = GetParam(val, 12); + sp.upgrade2 = GetParam(val, 13); + sp.upgrade3 = GetParam(val, 14); + sp.upradecount = atoi(GetParam(val, 10)); + sp.x = atoi(GetParam(val, 4)); + sp.y = atoi(GetParam(val, 3)); + sp.direction = atoi(GetParam(val, 5)); + sp.type = GetParam(val, 1); + + TruncSpace(sp.upgrade1); + TruncSpace(sp.upgrade2); + TruncSpace(sp.upgrade3); + + m_structurepaint.push_back(sp); + + int x = atoi(GetParam(val, 4)); + int y = atoi(GetParam(val, 3)); + int d, e; + int bid = buildingid[GetParam(val, 1)]; + for (d = 0; d < buildinginfo[bid].h; d++) { + for (e = 0; e < buildinginfo[bid].w; e++) { - STRUCTUREPAINT sp; - sp.col = ((CFinalSunDlg*)theApp.m_pMainWnd)->m_view.m_isoview->GetColor(GetParam(*sec.GetValue(i), 0)); - sp.strength = atoi(GetParam(*sec.GetValue(i), 2)); - sp.upgrade1 = GetParam(*sec.GetValue(i), 12); - sp.upgrade2 = GetParam(*sec.GetValue(i), 13); - sp.upgrade3 = GetParam(*sec.GetValue(i), 14); - sp.upradecount = atoi(GetParam(*sec.GetValue(i), 10)); - sp.x = atoi(GetParam(*sec.GetValue(i), 4)); - sp.y = atoi(GetParam(*sec.GetValue(i), 3)); - sp.direction = atoi(GetParam(*sec.GetValue(i), 5)); - sp.type = GetParam(*sec.GetValue(i), 1); - - TruncSpace(sp.upgrade1); - TruncSpace(sp.upgrade2); - TruncSpace(sp.upgrade3); - - m_structurepaint.push_back(sp); - - int x = atoi(GetParam(*sec.GetValue(i), 4)); - int y = atoi(GetParam(*sec.GetValue(i), 3)); - int d, e; - int bid = buildingid[GetParam(*sec.GetValue(i), 1)]; - for (d = 0;d < buildinginfo[bid].h;d++) + int pos = (x + d) + (y + e) * GetIsoSize(); + if (pos < fielddata_size) { - for (e = 0;e < buildinginfo[bid].w;e++) - { - int pos = (x + d) + (y + e) * GetIsoSize(); - if (pos < fielddata_size) - { - fielddata[pos].structure = i; - fielddata[pos].structuretype = bid; - } - - Mini_UpdatePos(x + d, y + e, IsMultiplayer()); - } + fielddata[pos].structure = i; + fielddata[pos].structuretype = bid; } - + Mini_UpdatePos(x + d, y + e, IsMultiplayer()); } } } @@ -1698,127 +1638,104 @@ void CMapData::UpdateTerrain(BOOL bSave, int num) { vector& t = m_terrain; - if (bSave == FALSE) - { - if (m_mapfile.sections.find("Terrain") == m_mapfile.sections.end() || m_mapfile.sections["Terrain"].values.size() <= 0) + if (bSave == FALSE) { + if (m_mapfile["Terrain"].Size() <= 0) { return; + } + if (num >= 0) { + return; + } + t.clear(); + t.reserve(100); - if (num < 0) - { - t.clear(); - t.reserve(100); - - int i; - for (i = 0;i < GetIsoSize() * GetIsoSize();i++) - { - fielddata[i].terrain = -1; - } - - - - CIniFileSection& sec = m_mapfile.sections["Terrain"]; - - for (i = 0;i < sec.values.size();i++) - { - int x, y; - PosToXY(*sec.GetValueName(i), &x, &y); - - // check for valid coordinates ; MW May 17th 2001 - ASSERT(x >= 0 && x < GetIsoSize()); - ASSERT(y >= 0 && y < GetIsoSize()); - if (x < 0 || x >= GetIsoSize() || y < 0 || y >= GetIsoSize()) - { - // invalid coordinates - ignore in release - } - else - { - TERRAIN td; - td.deleted = 0; - td.type = *sec.GetValue(i); - td.x = x; - td.y = y; - - t.push_back(td); - - int pos = x + y * GetIsoSize(); - fielddata[pos].terrain = i; - fielddata[pos].terraintype = terrainid[td.type]; - } - } - - m_mapfile.sections.erase("Terrain"); - + for (auto i = 0; i < GetIsoSize() * GetIsoSize(); i++) { + fielddata[i].terrain = -1; } + auto const& sec = m_mapfile["Terrain"]; + + for (auto i = 0; i < sec.Size(); i++) { + int x, y; + PosToXY(*sec.GetValueName(i), &x, &y); + + // check for valid coordinates ; MW May 17th 2001 + ASSERT(x >= 0 && x < GetIsoSize()); + ASSERT(y >= 0 && y < GetIsoSize()); + if (x < 0 || x >= GetIsoSize() || y < 0 || y >= GetIsoSize()) { + // invalid coordinates - ignore in release + continue; + } + TERRAIN td; + td.deleted = 0; + td.type = sec.Nth(i).second; + td.x = x; + td.y = y; + + t.push_back(td); + + int pos = x + y * GetIsoSize(); + fielddata[pos].terrain = i; + fielddata[pos].terraintype = terrainid[td.type]; + } + m_mapfile.DeleteSection("Terrain"); + return; } - else + + + //if(num<0) { + //if(m_mapfile.sections.find("Terrain")!=m_mapfile.sections.end()) MessageBox(0,"Reupdate!","",0); + m_mapfile.DeleteSection("Terrain"); - //if(num<0) - { - //if(m_mapfile.sections.find("Terrain")!=m_mapfile.sections.end()) MessageBox(0,"Reupdate!","",0); - m_mapfile.sections.erase("Terrain"); - int i; + for (auto i = 0; i < t.size(); i++) { + TERRAIN& td = t[i]; + if (!td.deleted) { + char j1[15]; + char k1[15]; - for (i = 0;i < t.size();i++) - { - TERRAIN& td = t[i]; - if (!td.deleted) + int x, y; + x = td.x; + y = td.y; + + itoa(y, j1, 10); + if (strlen(j1) < 3) { - char j1[15]; - char k1[15]; - - int x, y; - x = td.x; - y = td.y; - - itoa(y, j1, 10); - if (strlen(j1) < 3) - { - strcpy_safe(j1 + 1, j1); - j1[0] = '0'; - } - if (strlen(j1) < 3) - { - strcpy_safe(j1 + 1, j1); - j1[0] = '0'; - } - itoa(x, k1, 10); - strcat(k1, j1); - - - m_mapfile.sections["Terrain"].values[k1] = td.type; + strcpy_safe(j1 + 1, j1); + j1[0] = '0'; } + if (strlen(j1) < 3) + { + strcpy_safe(j1 + 1, j1); + j1[0] = '0'; + } + itoa(x, k1, 10); + strcat(k1, j1); + + + m_mapfile.SetString("Terrain", k1, td.type); } } - } } void CMapData::UpdateUnits(BOOL bSave) { - if (bSave == FALSE) - { + if (bSave == FALSE) { int i; - for (i = 0;i < GetIsoSize() * GetIsoSize();i++) - { + for (i = 0;i < GetIsoSize() * GetIsoSize();i++) { fielddata[i].unit = -1; } + auto const& sec = m_mapfile["Units"]; - if (m_mapfile.sections.find("Units") != m_mapfile.sections.end()) - { - CIniFileSection& sec = m_mapfile.sections["Units"]; - - for (i = 0;i < sec.values.size();i++) - { - int x = atoi(GetParam(*sec.GetValue(i), 4)); - int y = atoi(GetParam(*sec.GetValue(i), 3)); - int pos = x + y * GetIsoSize(); - if (pos < fielddata_size) fielddata[pos].unit = i; - - Mini_UpdatePos(x, y, IsMultiplayer()); + for (i = 0; i < sec.Size(); i++) { + int x = atoi(GetParam(sec.Nth(i).second, 4)); + int y = atoi(GetParam(sec.Nth(i).second, 3)); + int pos = x + y * GetIsoSize(); + if (pos < fielddata_size) { + fielddata[pos].unit = i; } + Mini_UpdatePos(x, y, IsMultiplayer()); } } @@ -1826,89 +1743,69 @@ void CMapData::UpdateUnits(BOOL bSave) void CMapData::UpdateWaypoints(BOOL bSave) { - if (bSave == FALSE) - { - int i; - for (i = 0;i < GetIsoSize() * GetIsoSize();i++) - { - fielddata[i].waypoint = -1; - } - - - if (m_mapfile.sections.find("Waypoints") != m_mapfile.sections.end()) - { - CIniFileSection& sec = m_mapfile.sections["Waypoints"]; - - for (i = 0;i < sec.values.size();i++) - { - int x, y; - PosToXY(*sec.GetValue(i), &x, &y); - - int pos = x + y * GetIsoSize(); - if (pos < 0 || pos >= fielddata_size) continue; - fielddata[pos].waypoint = i; - - int k, l; - for (k = -1;k < 2;k++) - for (l = -1;l < 2;l++) - Mini_UpdatePos(x + k, y + l, IsMultiplayer()); - } - } + if (bSave != FALSE) { + return; + } + int i; + for (i = 0; i < GetIsoSize() * GetIsoSize(); i++) { + fielddata[i].waypoint = -1; } + auto const& sec = m_mapfile["Waypoints"]; + + for (i = 0; i < sec.Size(); i++) { + int x, y; + PosToXY(sec.Nth(i).second, &x, &y); + + int pos = x + y * GetIsoSize(); + if (pos < 0 || pos >= fielddata_size) continue; + fielddata[pos].waypoint = i; + + int k, l; + for (k = -1; k < 2; k++) + for (l = -1; l < 2; l++) + Mini_UpdatePos(x + k, y + l, IsMultiplayer()); + } } void CMapData::UpdateNodes(BOOL bSave) { - if (bSave == FALSE) - { - int i; + if (bSave != FALSE) { + return; + } - for (i = 0;i < GetIsoSize() * GetIsoSize();i++) - { - fielddata[i].node.index = -1; - fielddata[i].node.type = -1; - fielddata[i].node.house = ""; - } + for (auto i = 0; i < GetIsoSize() * GetIsoSize(); i++) { + fielddata[i].node.index = -1; + fielddata[i].node.type = -1; + fielddata[i].node.house = ""; + } - if (m_mapfile.sections.find(MAPHOUSES) != m_mapfile.sections.end()) - { + for (auto const& [seq, id] : m_mapfile[MAPHOUSES]) { + auto const& sec = m_mapfile.GetSection(id); + int nodeCount = sec.GetInteger("NodeCount"); + for (auto idx = 0; idx < nodeCount; idx++) { + CString nodeName; + GetNodeName(nodeName, idx); + auto const& nodeVal = sec.GetString(nodeName); + CString type, sx, sy; + type = GetParam(nodeVal, 0); + sy = GetParam(nodeVal, 1); + sx = GetParam(nodeVal, 2); - for (i = 0;i < m_mapfile.sections[MAPHOUSES].values.size();i++) - { - CIniFileSection& sec = m_mapfile.sections[*m_mapfile.sections[MAPHOUSES].GetValue(i)]; - int c = atoi(sec.values["NodeCount"]); - - int e; - for (e = 0;e < c;e++) - { - CString p; - GetNodeName(p, e); - - CString type, sx, sy; - type = GetParam(sec.values[p], 0); - sy = GetParam(sec.values[p], 1); - sx = GetParam(sec.values[p], 2); - - int x = atoi(sx); - int y = atoi(sy); - int bid = buildingid[type]; - int d, f; - for (d = 0;d < buildinginfo[bid].h;d++) - { - for (f = 0;f < buildinginfo[bid].w;f++) - { - int pos = x + d + (y + f) * GetIsoSize(); - fielddata[pos].node.type = buildingid[type]; - fielddata[pos].node.house = *m_mapfile.sections[MAPHOUSES].GetValue(i); - fielddata[pos].node.index = e; - } - } + int x = atoi(sx); + int y = atoi(sy); + int bid = buildingid[type]; + int d, f; + for (d = 0; d < buildinginfo[bid].h; d++) { + for (f = 0; f < buildinginfo[bid].w; f++) { + int pos = x + d + (y + f) * GetIsoSize(); + fielddata[pos].node.type = buildingid[type]; + fielddata[pos].node.house = id; + fielddata[pos].node.index = idx; } } } } - } void CMapData::UpdateOverlay(BOOL bSave) @@ -1949,27 +1846,23 @@ void CMapData::UpdateOverlay(BOOL bSave) void CMapData::UpdateCelltags(BOOL bSave) { - if (bSave == FALSE) - { - int i; - for (i = 0;i < GetIsoSize() * GetIsoSize();i++) - { - fielddata[i].celltag = -1; - } + if (bSave != FALSE) { + return; + } + int i; + for (i = 0; i < GetIsoSize() * GetIsoSize(); i++) { + fielddata[i].celltag = -1; + } + auto const& sec = m_mapfile["CellTags"]; - if (m_mapfile.sections.find("CellTags") != m_mapfile.sections.end()) - { - CIniFileSection& sec = m_mapfile.sections["CellTags"]; + for (i = 0; i < sec.Size(); i++) { + int x, y; + PosToXY(sec.Nth(i).first, &x, &y); - for (i = 0;i < sec.values.size();i++) - { - int x, y; - PosToXY(*sec.GetValueName(i), &x, &y); - - int pos = x + y * GetIsoSize(); - if (pos < fielddata_size) fielddata[pos].celltag = i; - } + int pos = x + y * GetIsoSize(); + if (pos < fielddata_size) { + fielddata[pos].celltag = i; } } } @@ -2038,10 +1931,14 @@ void CMapData::DeleteWaypoint(DWORD dwIndex) int x = pos % m_IsoSize; int y = pos / m_IsoSize; + auto const pSec = m_mapfile.TryGetSection("Waypoints"); + ASSERT(pSec != nullptr); - - m_mapfile.sections["Waypoints"].values.erase(*m_mapfile.sections["Waypoints"].GetValueName(dwIndex)); - if (!m_noAutoObjectUpdate) UpdateWaypoints(FALSE); + pSec->RemoveAt(dwIndex); + + if (!m_noAutoObjectUpdate) { + UpdateWaypoints(FALSE); + } int k, l; for (k = -1;k < 2;k++) @@ -2051,45 +1948,60 @@ void CMapData::DeleteWaypoint(DWORD dwIndex) void CMapData::DeleteCelltag(DWORD dwIndex) { - if (dwIndex >= GetCelltagCount()) return; + if (dwIndex >= GetCelltagCount()) { + return; + } - m_mapfile.sections["CellTags"].values.erase(*m_mapfile.sections["CellTags"].GetValueName(dwIndex)); - if (!m_noAutoObjectUpdate) UpdateCelltags(FALSE); + auto const pSec = m_mapfile.TryGetSection("CellTags"); + ASSERT(pSec != nullptr); + pSec->RemoveAt(dwIndex); + + if (!m_noAutoObjectUpdate) { + UpdateCelltags(FALSE); + } } void CMapData::DeleteUnit(DWORD dwIndex) { if (dwIndex >= GetUnitCount()) return; - CIniFileSection& sec = m_mapfile.sections["Units"]; - int x = atoi(GetParam(*sec.GetValue(dwIndex), 4)); - int y = atoi(GetParam(*sec.GetValue(dwIndex), 3)); + auto const& pSec = m_mapfile.TryGetSection("Units"); + ASSERT(pSec != nullptr); + int x = atoi(GetParam(pSec->Nth(dwIndex).second, 4)); + int y = atoi(GetParam(pSec->Nth(dwIndex).second, 3)); + pSec->RemoveAt(dwIndex); - m_mapfile.sections["Units"].values.erase(*m_mapfile.sections["Units"].GetValueName(dwIndex)); - if (!m_noAutoObjectUpdate) UpdateUnits(FALSE); + if (!m_noAutoObjectUpdate) { + UpdateUnits(FALSE); + } Mini_UpdatePos(x, y, IsMultiplayer()); } void CMapData::DeleteStructure(DWORD dwIndex) { - if (dwIndex >= GetStructureCount()) return; + if (dwIndex >= GetStructureCount()) { + return; + } - CIniFileSection& sec = m_mapfile.sections["Structures"]; - int x = atoi(GetParam(*sec.GetValue(dwIndex), 4)); - int y = atoi(GetParam(*sec.GetValue(dwIndex), 3)); - CString type = GetParam(*sec.GetValue(dwIndex), 1); + auto const& pSec = m_mapfile.TryGetSection("Structures"); + ASSERT(pSec != nullptr); + auto const& val = pSec->Nth(dwIndex).second; + int x = atoi(GetParam(val, 4)); + int y = atoi(GetParam(val, 3)); + CString type = GetParam(val, 1); - m_mapfile.sections["Structures"].values.erase(*m_mapfile.sections["Structures"].GetValueName(dwIndex)); - if (!m_noAutoObjectUpdate) UpdateStructures(FALSE); + pSec->RemoveAt(dwIndex); + + if (!m_noAutoObjectUpdate) { + UpdateStructures(FALSE); + } int d, e; int bid = buildingid[type]; - for (d = 0;d < buildinginfo[bid].h;d++) - { - for (e = 0;e < buildinginfo[bid].w;e++) - { + for (d = 0;d < buildinginfo[bid].h;d++) { + for (e = 0;e < buildinginfo[bid].w;e++) { int pos = (x + d) + (y + e) * GetIsoSize(); Mini_UpdatePos(x + d, y + e, IsMultiplayer()); @@ -2101,13 +2013,17 @@ void CMapData::DeleteAircraft(DWORD dwIndex) { if (dwIndex >= GetAircraftCount()) return; - CIniFileSection& sec = m_mapfile.sections["Aircraft"]; - int x = atoi(GetParam(*sec.GetValue(dwIndex), 4)); - int y = atoi(GetParam(*sec.GetValue(dwIndex), 3)); + auto const& pSec = m_mapfile.TryGetSection("Aircraft"); + ASSERT(pSec != nullptr); + auto const& val = pSec->Nth(dwIndex).second; + int x = atoi(GetParam(val, 4)); + int y = atoi(GetParam(val, 3)); + pSec->RemoveAt(dwIndex); - m_mapfile.sections["Aircraft"].values.erase(*m_mapfile.sections["Aircraft"].GetValueName(dwIndex)); - if (!m_noAutoObjectUpdate) UpdateAircraft(FALSE); + if (!m_noAutoObjectUpdate) { + UpdateAircraft(FALSE); + } Mini_UpdatePos(x, y, IsMultiplayer()); } @@ -2141,23 +2057,23 @@ void CMapData::DeleteTerrain(DWORD dwIndex) void CMapData::DeleteNode(LPCTSTR lpHouse, DWORD dwIndex) { - CString p; // p is last node - GetNodeName(p, atoi(m_mapfile.sections[lpHouse].values["NodeCount"]) - 1); + CString nodeName; // p is last node + auto const nodeCount = m_mapfile.GetInteger(lpHouse, "NodeCount"); + GetNodeName(nodeName, nodeCount - 1); - char c[50]; - itoa(atoi(m_mapfile.sections[lpHouse].values["NodeCount"]) - 1, c, 10); - - int i; - for (i = dwIndex;i < atoi(m_mapfile.sections[lpHouse].values["NodeCount"]) - 1;i++) - { - CString d1, d2; - GetNodeName(d1, i); - GetNodeName(d2, i + 1); - m_mapfile.sections[lpHouse].values[d1] = m_mapfile.sections[lpHouse].values[d2]; + for (auto i = dwIndex; i < nodeCount - 1; i++) { + CString prevNodeName, nextNodeName; + GetNodeName(prevNodeName, i); + GetNodeName(nextNodeName, i + 1); + m_mapfile.SetString(lpHouse, prevNodeName, m_mapfile.GetString(lpHouse, nextNodeName)); } - m_mapfile.sections[lpHouse].values.erase(p); - m_mapfile.sections[lpHouse].values["NodeCount"] = c; + auto const& pSec = m_mapfile.TryGetSection(lpHouse); + pSec->RemoveAt(dwIndex); + + char nodeCountStr[50]; + itoa(nodeCount - 1, nodeCountStr, 10); + m_mapfile.SetString(lpHouse, "NodeCount", nodeCountStr); UpdateNodes(FALSE); } @@ -2192,8 +2108,10 @@ BOOL CMapData::AddWaypoint(CString lpID, DWORD dwPos) //MessageBox(0,k,"",0); - m_mapfile.sections["Waypoints"].values[id] = k; - if (!m_noAutoObjectUpdate) UpdateWaypoints(FALSE); + m_mapfile.SetString("Waypoints", id, k); + if (!m_noAutoObjectUpdate) { + UpdateWaypoints(FALSE); + } return TRUE; } @@ -2202,11 +2120,12 @@ BOOL CMapData::AddWaypoint(CString lpID, DWORD dwPos) void CMapData::GetStructureData(DWORD dwIndex, STRUCTURE* lpStructure) const { - const auto section = m_mapfile.GetSection("Structures"); - if (!section || dwIndex >= section->values.size()) + auto const& section = m_mapfile.GetSection("Structures"); + if (dwIndex >= section.Size()) { return; + } - CString data = *section->GetValue(dwIndex); + auto const& data = section.Nth(dwIndex).second; lpStructure->house = GetParam(data, 0); lpStructure->type = GetParam(data, 1); @@ -2230,11 +2149,11 @@ void CMapData::GetStructureData(DWORD dwIndex, STRUCTURE* lpStructure) const void CMapData::GetStdStructureData(DWORD dwIndex, STDOBJECTDATA* lpStdStructure) const { - const auto section = m_mapfile.GetSection("Structures"); - if (!section || dwIndex >= section->values.size()) + auto const& section = m_mapfile.GetSection("Structures"); + if (dwIndex >= section.Size()) { return; - - CString data = *section->GetValue(dwIndex); + } + auto const& data = section.Nth(dwIndex).second; lpStdStructure->house = GetParam(data, 0); lpStdStructure->type = GetParam(data, 1); @@ -2255,32 +2174,28 @@ BOOL CMapData::AddNode(NODE* lpNode, WORD dwPos) node.x.Format("%d", dwPos % Map->GetIsoSize()); node.y.Format("%d", dwPos / Map->GetIsoSize()); node.house = GetHouseID(0); - node.type = *rules.sections["BuildingTypes"].GetValue(0); + node.type = rules["BuildingTypes"].Nth(0).second; } - if (m_mapfile.sections.find(HOUSES) == m_mapfile.sections.end() || m_mapfile.sections[HOUSES].values.size() == 0) - { + if (m_mapfile.GetSection(HOUSES).Size() == 0) { return FALSE; } + auto nodeCount = m_mapfile.GetInteger(node.house, "NodeCount"); - int c = atoi(m_mapfile.sections[(LPCTSTR)node.house].values["NodeCount"]); + nodeCount++; + char newNodeCountStr[50]; + itoa(nodeCount, newNodeCountStr, 10); + m_mapfile.SetString(node.house, "NodeCount", newNodeCountStr); - c++; - char sc[50]; - itoa(c, sc, 10); - m_mapfile.sections[(LPCTSTR)node.house].values["NodeCount"] = sc; - - c--; + nodeCount--; CString p; - GetNodeName(p, c); + GetNodeName(p, nodeCount); + auto&& nodeRecord = node.type + + "," + node.y + "," + node.x; - m_mapfile.sections[(LPCTSTR)node.house].values[p] = node.type; - m_mapfile.sections[(LPCTSTR)node.house].values[p] += ","; - m_mapfile.sections[(LPCTSTR)node.house].values[p] += node.y; - m_mapfile.sections[(LPCTSTR)node.house].values[p] += ","; - m_mapfile.sections[(LPCTSTR)node.house].values[p] += node.x; + m_mapfile.SetString(node.house, p, std::move(nodeRecord)); UpdateNodes(FALSE); @@ -2483,10 +2398,8 @@ BOOL CMapData::AddStructure(STRUCTURE* lpStructure, LPCTSTR lpType, LPCTSTR lpHo CString id = GetFree("Structures"); - if (suggestedID.GetLength() > 0) - { - if (m_mapfile.sections["Structures"].values.find(suggestedID) == m_mapfile.sections["Structures"].values.end()) - id = suggestedID; + if (!suggestedID.IsEmpty() && !m_mapfile["Structures"].Exists(suggestedID)) { + id = suggestedID; } CString value; @@ -2495,9 +2408,11 @@ BOOL CMapData::AddStructure(STRUCTURE* lpStructure, LPCTSTR lpType, LPCTSTR lpHo structure.flag2 + "," + structure.energy + "," + structure.upgradecount + "," + structure.spotlight + "," + structure.upgrade1 + "," + structure.upgrade2 + "," + structure.upgrade3 + "," + structure.flag3 + "," + structure.flag4; - m_mapfile.sections["Structures"].values[id] = (LPCTSTR)value; + m_mapfile.SetString("Structures", id, value); - if (!m_noAutoObjectUpdate) UpdateStructures(FALSE); + if (!m_noAutoObjectUpdate) { + UpdateStructures(FALSE); + } return TRUE; } @@ -2510,60 +2425,32 @@ void CMapData::InitializeUnitTypes() terrainid.clear(); int i; - m_overlayCredits[OverlayCredits_Riparius] = atoi(m_mapfile.GetValueByName("Riparius", "Value", rules.sections["Riparius"].AccessValueByName("Value"))); - m_overlayCredits[OverlayCredits_Cruentus] = atoi(m_mapfile.GetValueByName("Cruentus", "Value", rules.sections["Cruentus"].AccessValueByName("Value"))); - m_overlayCredits[OverlayCredits_Vinifera] = atoi(m_mapfile.GetValueByName("Vinifera", "Value", rules.sections["Vinifera"].AccessValueByName("Value"))); - m_overlayCredits[OverlayCredits_Aboreus] = atoi(m_mapfile.GetValueByName("Aboreus", "Value", rules.sections["Aboreus"].AccessValueByName("Value"))); - for (i = 0;i < rules.sections["BuildingTypes"].values.size();i++) - { - CString type = *rules.sections["BuildingTypes"].GetValue(i); + m_overlayCredits[OverlayCredits_Riparius] = m_mapfile.GetInteger("Riparius", "Value"); + m_overlayCredits[OverlayCredits_Cruentus] = m_mapfile.GetInteger("Cruentus", "Value"); + m_overlayCredits[OverlayCredits_Vinifera] = m_mapfile.GetInteger("Vinifera", "Value"); + m_overlayCredits[OverlayCredits_Aboreus] = m_mapfile.GetInteger("Aboreus", "Value"); - int n = GetBuildingNumber(type); - buildingid[type] = n; + for (auto const& [seq, typeId] : rules["BuildingTypes"]) { + buildingid[typeId] = GetBuildingNumber(typeId); + } + for (auto const& [seq, typeId] : m_mapfile["BuildingTypes"]) { + buildingid[typeId] = GetBuildingNumber(typeId); } - for (i = 0;i < m_mapfile.sections["BuildingTypes"].values.size();i++) - { - CString type = *m_mapfile.sections["BuildingTypes"].GetValue(i); - - int n = GetBuildingNumber(type); - buildingid[type] = n; + for (auto const& [seq, typeId] : rules["TerrainTypes"]) { + terrainid[typeId] = GetTerrainNumber(typeId); } - - for (i = 0;i < rules.sections["TerrainTypes"].values.size();i++) - { - CString type = *rules.sections["TerrainTypes"].GetValue(i); - - int n = GetTerrainNumber(type); - terrainid[type] = n; - } - - for (i = 0;i < m_mapfile.sections["TerrainTypes"].values.size();i++) - { - CString type = *m_mapfile.sections["TerrainTypes"].GetValue(i); - - int n = GetTerrainNumber(type); - terrainid[type] = n; + for (auto const& [seq, typeId] : m_mapfile["TerrainTypes"]) { + terrainid[typeId] = GetTerrainNumber(typeId); } #ifdef SMUDGE_SUPP - - for (i = 0;i < rules.sections["SmudgeTypes"].values.size();i++) - { - CString type = *rules.sections["SmudgeTypes"].GetValue(i); - - int n = GetSmudgeNumber(type); - smudgeid[type] = n; + for (auto const& [seq, typeId] : rules["SmudgeTypes"]) { + smudgeid[typeId] = GetSmudgeNumber(typeId); } - - for (i = 0;i < m_mapfile.sections["SmudgeTypes"].values.size();i++) - { - CString type = *m_mapfile.sections["SmudgeTypes"].GetValue(i); - - int n = GetSmudgeNumber(type); - smudgeid[type] = n; + for (auto const& [seq, typeId] : m_mapfile["SmudgeTypes"]) { + smudgeid[typeId] = GetSmudgeNumber(typeId); } - #endif @@ -2649,11 +2536,12 @@ void CMapData::GetInfantryData(DWORD dwIndex, INFANTRY* lpInfantry) const void CMapData::GetUnitData(DWORD dwIndex, UNIT* lpUnit) const { - const auto section = m_mapfile.GetSection("Units"); - if (!section || dwIndex >= section->values.size()) + auto const& section = m_mapfile.GetSection("Units"); + if (dwIndex >= section.Size()) { return; + } - CString data = *section->GetValue(dwIndex); + auto const& data = section.Nth(dwIndex).second; lpUnit->house = GetParam(data, 0); lpUnit->type = GetParam(data, 1); @@ -2673,11 +2561,12 @@ void CMapData::GetUnitData(DWORD dwIndex, UNIT* lpUnit) const void CMapData::GetAircraftData(DWORD dwIndex, AIRCRAFT* lpAircraft) const { - const auto section = m_mapfile.GetSection("Aircraft"); - if (!section || dwIndex >= section->values.size()) + auto const& section = m_mapfile.GetSection("Aircraft"); + if (dwIndex >= section.Size()) { return; + } - CString data = *section->GetValue(dwIndex); + auto const& data = section.Nth(dwIndex).second; lpAircraft->house = GetParam(data, 0); lpAircraft->type = GetParam(data, 1); @@ -2713,7 +2602,7 @@ BOOL CMapData::AddCelltag(LPCTSTR lpTag, DWORD dwPos) itoa(dwPos % GetIsoSize(), k, 10); strcat(k, j); - m_mapfile.sections["CellTags"].values[k] = lpTag; + m_mapfile.SetString("CellTags", k, lpTag); if (!m_noAutoObjectUpdate) UpdateCelltags(FALSE); return TRUE; @@ -2721,17 +2610,16 @@ BOOL CMapData::AddCelltag(LPCTSTR lpTag, DWORD dwPos) void CMapData::GetCelltagData(DWORD dwIndex, CString* lpTag, DWORD* lpdwPos) const { - const auto section = m_mapfile.GetSection("CellTags"); - if (!section || dwIndex >= section->values.size()) + auto const& section = m_mapfile.GetSection("CellTags"); + if (dwIndex >= section.Size()) { return; + } + + auto const& [pos, tag] = section.Nth(dwIndex); int x, y; - CString pos; - - pos = *section->GetValueName(dwIndex); PosToXY(pos, &x, &y); - const auto tag = section->GetValueByName(pos); *lpTag = tag; *lpdwPos = x + y * GetIsoSize(); } @@ -2766,10 +2654,8 @@ BOOL CMapData::AddAircraft(AIRCRAFT* lpAircraft, LPCTSTR lpType, LPCTSTR lpHouse CString id = GetFree("Aircraft"); - if (suggestedID.GetLength() > 0) - { - if (m_mapfile.sections["Aircraft"].values.find(suggestedID) == m_mapfile.sections["Aircraft"].values.end()) - id = suggestedID; + if (!suggestedID.IsEmpty() && !m_mapfile["Aircraft"].Exists(suggestedID)) { + id = suggestedID; } CString value; @@ -2777,9 +2663,11 @@ BOOL CMapData::AddAircraft(AIRCRAFT* lpAircraft, LPCTSTR lpType, LPCTSTR lpHouse aircraft.x + "," + aircraft.direction + "," + aircraft.action + "," + aircraft.tag + "," + aircraft.flag1 + "," + aircraft.flag2 + "," + aircraft.flag3 + "," + aircraft.flag4; - m_mapfile.sections["Aircraft"].values[id] = value; + m_mapfile.SetString("Aircraft", id, value); - if (!m_noAutoObjectUpdate) UpdateAircraft(FALSE); + if (!m_noAutoObjectUpdate) { + UpdateAircraft(FALSE); + } return TRUE; } @@ -2817,10 +2705,8 @@ BOOL CMapData::AddUnit(UNIT* lpUnit, LPCTSTR lpType, LPCTSTR lpHouse, DWORD dwPo CString id = GetFree("Units"); - if (suggestedID.GetLength() > 0) - { - if (m_mapfile.sections["Units"].values.find(suggestedID) == m_mapfile.sections["Units"].values.end()) - id = suggestedID; + if (!suggestedID.IsEmpty() && !m_mapfile["Units"].Exists(suggestedID)) { + id = suggestedID; } CString value; @@ -2828,9 +2714,11 @@ BOOL CMapData::AddUnit(UNIT* lpUnit, LPCTSTR lpType, LPCTSTR lpHouse, DWORD dwPo unit.x + "," + unit.direction + "," + unit.action + "," + unit.tag + "," + unit.flag1 + "," + unit.flag2 + "," + unit.flag3 + "," + unit.flag4 + "," + unit.flag5 + "," + unit.flag6; - m_mapfile.sections["Units"].values[id] = value; + m_mapfile.SetString("Units", id, value); - if (!m_noAutoObjectUpdate) UpdateUnits(FALSE); + if (!m_noAutoObjectUpdate) { + UpdateUnits(FALSE); + } return TRUE; } @@ -2966,30 +2854,40 @@ BOOL CMapData::IsGroundObjectAt(DWORD dwPos) const void CMapData::GetWaypointData(DWORD dwIndex, CString* lpID, DWORD* lpdwPos) const { - if (lpID) *lpID = ""; - if (lpdwPos) *lpdwPos = 0; + if (lpID) { + *lpID = ""; + } + if (lpdwPos) { + *lpdwPos = 0; + } - const auto section = m_mapfile.GetSection("Waypoints"); - if (!section || dwIndex >= section->values.size()) + auto const& section = m_mapfile.GetSection("Waypoints"); + if (dwIndex >= section.Size()) { return; + } - CString data = *section->GetValue(dwIndex); + auto const& [id, data] = section.Nth(dwIndex); int x, y; PosToXY(data, &x, &y); - if (lpID) *lpID = *section->GetValueName(dwIndex); - if (lpdwPos) *lpdwPos = x + y * GetIsoSize(); + if (lpID) { + *lpID = id; + } + if (lpdwPos) { + *lpdwPos = x + y * GetIsoSize(); + } } void CMapData::GetStdAircraftData(DWORD dwIndex, STDOBJECTDATA* lpStdAircraft) const { - const auto section = m_mapfile.GetSection("Aircraft"); - if (!section || dwIndex >= section->values.size()) + auto const& section = m_mapfile.GetSection("Aircraft"); + if (dwIndex >= section.Size()) { return; + } - CString data = *section->GetValue(dwIndex); + auto const& data = section.Nth(dwIndex).second; lpStdAircraft->house = GetParam(data, 0); lpStdAircraft->type = GetParam(data, 1); @@ -3000,11 +2898,12 @@ void CMapData::GetStdAircraftData(DWORD dwIndex, STDOBJECTDATA* lpStdAircraft) c void CMapData::GetStdUnitData(DWORD dwIndex, STDOBJECTDATA* lpStdUnit) const { - const auto section = m_mapfile.GetSection("Units"); - if (!section || dwIndex >= section->values.size()) + auto const& section = m_mapfile.GetSection("Units"); + if (dwIndex >= section.Size()) { return; + } - CString data = *section->GetValue(dwIndex); + auto const& data = section.Nth(dwIndex).second; lpStdUnit->house = GetParam(data, 0); lpStdUnit->type = GetParam(data, 1); @@ -3020,20 +2919,17 @@ DWORD CMapData::GetInfantryCount() const DWORD CMapData::GetUnitCount() const { - const auto section = m_mapfile.GetSection("Units"); - return section ? section->values.size() : 0; + return m_mapfile.GetSection("Units").Size(); } DWORD CMapData::GetStructureCount() const { - const auto section = m_mapfile.GetSection("Structures"); - return section ? section->values.size() : 0; + return m_mapfile.GetSection("Structures").Size(); } DWORD CMapData::GetAircraftCount() const { - const auto section = m_mapfile.GetSection("Aircraft"); - return section ? section->values.size() : 0; + return m_mapfile.GetSection("Aircraft").Size(); } DWORD CMapData::GetTerrainCount() const @@ -3052,58 +2948,50 @@ WCHAR* CMapData::GetUnitName(LPCTSTR lpID) const { WCHAR* res = NULL; - if (g_data.sections["Rename"].FindName(lpID) >= 0) - { - CCStrings[lpID].SetString((LPSTR)(LPCSTR)GetLanguageStringACP(g_data.sections["Rename"].values[(LPCSTR)lpID])); + auto const& renameStr = g_data.GetString("Rename", lpID); + if (!renameStr.IsEmpty()) { + CCStrings[lpID].SetString(GetLanguageStringACP(renameStr)); res = CCStrings[lpID].wString; return res; } - if (CCStrings.find(lpID) != CCStrings.end() && CCStrings[lpID].len > 0) res = CCStrings[lpID].wString; + if (CCStrings.find(lpID) != CCStrings.end() && CCStrings[lpID].len > 0) { + res = CCStrings[lpID].wString; + } - if (!res && m_mapfile.sections.find(lpID) != m_mapfile.sections.end()) - { - const auto section = m_mapfile.GetSection(lpID); - if (section && section->values.find("Name") != section->values.end()) - { - CCStrings[lpID].SetString(section->values.at("Name")); + if (!res) { + auto const& section = m_mapfile.GetSection(lpID); + auto const& nameVal = section.GetString("Name"); + if (!nameVal.IsEmpty()) { + CCStrings[lpID].SetString(nameVal); res = CCStrings[lpID].wString; } } - if (!res && rules.sections.find(lpID) != rules.sections.end()) - { - const auto section = rules.GetSection(lpID); - if (section && section->values.find("Name") != section->values.end()) - { - CCStrings[lpID].SetString(section->values.at("Name")); + if (!res) { + auto const& nameStr = rules.GetString(lpID, "Name"); + if (!nameStr.IsEmpty()) { + CCStrings[lpID].SetString(nameStr); res = CCStrings[lpID].wString; } } - if (!res) - { + if (!res) { CCStrings[lpID].SetString(L"MISSING", 7); res = CCStrings[lpID].wString; } - - return res; - - //return CString(""); } DWORD CMapData::GetCelltagCount() const { - const auto section = m_mapfile.GetSection("CellTags"); - return section ? section->values.size() : 0; + return m_mapfile.GetSection("CellTags").Size(); } DWORD CMapData::GetWaypointCount() const { - const auto section = m_mapfile.GetSection("Waypoints"); - return section ? section->values.size() : 0; + return m_mapfile.GetSection("Waypoints").Size(); } void CMapData::DeleteRulesSections() @@ -3111,87 +2999,93 @@ void CMapData::DeleteRulesSections() int i; // delete any rules sections except the types lists (we need those to get the data of new units in the map)... - for (i = 0; i < m_mapfile.sections.size(); i++) - { - CString name = *m_mapfile.GetSectionName(i); - - if (IsRulesSection(name) && name.Find("Types") < 0) - { - m_mapfile.sections.erase(name); + for (auto it = m_mapfile.begin(); it != m_mapfile.end();) { + auto const& name = it->first; + if (IsRulesSection(name) && name.Find("Types") < 0) { + // special care for deletion, this is a deletion in a loop + it = m_mapfile.DeleteAt(it); + continue; } + ++it; } // now delete these types lists... - for (i = 0; i < m_mapfile.sections.size(); i++) - { - CString name = *m_mapfile.GetSectionName(i); - - if (IsRulesSection(name)) - { - m_mapfile.sections.erase(name); + for (auto it = m_mapfile.begin(); it != m_mapfile.end();) { + auto const& name = it->first; + if (IsRulesSection(name)) { + // special care for deletion, this is a deletion in a loop + it = m_mapfile.DeleteAt(it); + continue; } + ++it; } } BOOL CMapData::IsRulesSection(LPCTSTR lpSection) { int i; - for (i = 0;i < GetHousesCount();i++) - if (GetHouseID(i) == lpSection) return FALSE; - - if (strcmp(lpSection, HOUSES) == NULL) return FALSE; - if (strcmp(lpSection, "VariableNames") == NULL) return FALSE; - - if (rules.sections.find(lpSection) != rules.sections.end()) return TRUE; - - - if (m_mapfile.sections.find("InfantryTypes") != m_mapfile.sections.end()) - if (m_mapfile.sections["InfantryTypes"].FindValue(lpSection) >= 0) - return TRUE; - - if (m_mapfile.sections.find("VehicleTypes") != m_mapfile.sections.end()) - if (m_mapfile.sections["VehicleTypes"].FindValue(lpSection) >= 0) - return TRUE; - - if (m_mapfile.sections.find("AircraftTypes") != m_mapfile.sections.end()) - if (m_mapfile.sections["AircraftTypes"].FindValue(lpSection) >= 0) - return TRUE; - - if (m_mapfile.sections.find("BuildingTypes") != m_mapfile.sections.end()) - if (m_mapfile.sections["BuildingTypes"].FindValue(lpSection) >= 0) - return TRUE; - - if (m_mapfile.sections.find("TerrainTypes") != m_mapfile.sections.end()) - if (m_mapfile.sections["TerrainTypes"].FindValue(lpSection) >= 0) - return TRUE; - - if ((CString)"IsoMapPack5" != lpSection && (CString)"OverlayPack" != lpSection && (CString)"OverlayDataPack" != lpSection && m_mapfile.sections.find(lpSection) != m_mapfile.sections.end()) - { - CIniFileSection& sec = m_mapfile.sections[lpSection]; - if (sec.FindName("ROF") > -1 && sec.FindName("Range") > -1 && - sec.FindName("Damage") > -1 && sec.FindName("Warhead") > -1) - return TRUE; // a weapon - - if (sec.FindName("Spread") > -1 && sec.FindName("Range") > -1 && - sec.FindName("Damage") > -1 && sec.FindName("Warhead") > -1) - return TRUE; // a warhead - - // check for projectile/warhead - for (i = 0;i < m_mapfile.sections.size();i++) - { - CString name = *m_mapfile.GetSectionName(i); - if ((CString)"IsoMapPack5" != name && (CString)"OverlayPack" != name && (CString)"OverlayDataPack" != name && (m_mapfile.GetSection(i)->FindName("Projectile") > -1 || m_mapfile.GetSection(i)->FindName("Warhead") > -1)) - { - // MW Bugfix: Check if is found in Projectile first... - // This may have caused several crashes while saving - if (m_mapfile.GetSection(i)->FindName("Projectile") >= 0) - if (*m_mapfile.GetSection(i)->GetValue(m_mapfile.GetSection(i)->FindName("Projectile")) == lpSection) - return TRUE; - } + for (i = 0; i < GetHousesCount(); i++) { + if (GetHouseID(i) == lpSection) { + return FALSE; } } + if (strcmp(lpSection, HOUSES) == NULL) { + return FALSE; + } + if (strcmp(lpSection, "VariableNames") == NULL) { + return FALSE; + } + if (rules.TryGetSection(lpSection) != nullptr) { + return TRUE; + } + + if (m_mapfile["InfantryTypes"].HasValue(lpSection)) { + return TRUE; + } + if (m_mapfile["VehicleTypes"].HasValue(lpSection)) { + return TRUE; + } + if (m_mapfile["AircraftTypes"].HasValue(lpSection)) { + return TRUE; + } + if (m_mapfile["BuildingTypes"].HasValue(lpSection)) { + return TRUE; + } + if (m_mapfile["TerrainTypes"].HasValue(lpSection)) { + return TRUE; + } + + auto const pMapSec = m_mapfile.TryGetSection(lpSection); + if ((CString)"IsoMapPack5" != lpSection + && (CString)"OverlayPack" != lpSection + && (CString)"OverlayDataPack" != lpSection + && pMapSec) { + if (pMapSec->FindIndex("ROF") > -1 && pMapSec->FindIndex("Range") > -1 && + pMapSec->FindIndex("Damage") > -1 && pMapSec->FindIndex("Warhead") > -1) + return TRUE; // a weapon + + if (pMapSec->FindIndex("Spread") > -1 && pMapSec->FindIndex("Range") > -1 && + pMapSec->FindIndex("Damage") > -1 && pMapSec->FindIndex("Warhead") > -1) + return TRUE; // a warhead + + // check for projectile/warhead + for (auto const& [name, sec] : m_mapfile) { + if ((CString)"IsoMapPack5" != name + && (CString)"OverlayPack" != name + && (CString)"OverlayDataPack" != name + && (sec.Exists("Projectile") || sec.Exists("Warhead"))) { + // MW Bugfix: Check if is found in Projectile first... + // This may have caused several crashes while saving + if (sec.Exists("Projectile")) { + if (sec.GetString("Projectile") == lpSection) { + return TRUE; + } + } + } + } + } return FALSE; @@ -3200,28 +3094,18 @@ BOOL CMapData::IsRulesSection(LPCTSTR lpSection) void CMapData::ExportRulesChanges(const char* filename) { CIniFile rul; - - int i; - for (i = 0;i < m_mapfile.sections.size();i++) - { - - CString name = *m_mapfile.GetSectionName(i); - - if (IsRulesSection(name)) - { - - rul.sections[name] = *m_mapfile.GetSection(i); - + for (auto const& [name, sec] : m_mapfile) { + if (IsRulesSection(name)) { + rul.SetSection(name, sec); } } - rul.SaveFile(std::string(filename)); } void CMapData::ImportRUL(LPCTSTR lpFilename) { m_mapfile.InsertFile(std::string(lpFilename), NULL); - m_mapfile.sections.erase("Editor"); + m_mapfile.DeleteSection("Editor"); UpdateBuildingInfo(); UpdateTreeInfo(); } @@ -3296,11 +3180,13 @@ void CMapData::UpdateMapFieldData(BOOL bSave) int replacement = 0; int ground = mfd->wGround; - if (ground == 0xFFFF) ground = 0; + if (ground == 0xFFFF) { + ground = 0; + } - if ((*tiledata)[ground].bReplacementCount && atoi((*tiles).sections["General"].values["BridgeSet"]) != (*tiledata)[ground].wTileSet) - { - replacement = rand() * (1 + (*tiledata)[ground].bReplacementCount) / RAND_MAX; + auto const& tile = (*tiledata)[ground]; + if (tile.bReplacementCount && tiles->GetInteger("General", "BridgeSet") != tile.wTileSet) { + replacement = rand() * (1 + tile.bReplacementCount) / RAND_MAX; } fielddata[pos].bRNDImage = replacement; @@ -3626,50 +3512,39 @@ void CMapData::UpdateMapFieldData(BOOL bSave) } } -void CMapData::UpdateBuildingInfo(LPCSTR lpUnitType) +// TODO: simplify this function, remove duplicated codes +void CMapData::UpdateBuildingInfo(const CString* lpUnitType) { CIniFile& ini = GetIniFile(); - if (!lpUnitType) - { + if (!lpUnitType) { memset(buildinginfo, 0, 0x0F00 * sizeof(BUILDING_INFO)); - int i; - for (i = 0;i < rules.sections["BuildingTypes"].values.size();i++) - { - - - CString type = *rules.sections["BuildingTypes"].GetValue(i); - CString artname = type; - - - if (rules.sections[type].values.find("Image") != rules.sections[type].values.end()) - { - artname = rules.sections[type].values["Image"]; - } - if (ini.sections.find(type) != ini.sections.end()) - { - if (ini.sections[type].values.find("Image") != ini.sections[type].values.end()) - { - artname = ini.sections[type].values["Image"]; - } - } + for (auto const& [seq, id] : rules.GetSection("BuildingTypes")) { + auto const& type = id; + auto artname = rules.GetStringOr(type, "Image", type); + artname = ini.GetStringOr(type, "Image", artname); int w, h; char d[6]; - memcpy(d, art.sections[artname].values["Foundation"], 1); + auto const& foundationStr = art[artname].GetString("Foundation"); + // TODO: foundationStr == "Custom" + d[0] = foundationStr[0]; d[1] = 0; w = atoi(d); - if (w == 0) w = 1; - memcpy(d, (LPCTSTR)art.sections[artname].values["Foundation"] + 2, 1); + if (w == 0) { + w = 1; + } + d[0] = foundationStr[2]; d[1] = 0; h = atoi(d); - if (h == 0) h = 1; + if (h == 0) { + h = 1; + } int n = Map->GetUnitTypeID(type); - if (n >= 0 && n < 0x0F00) - { + if (n >= 0 && n < 0x0F00) { buildinginfo[n].w = w; buildinginfo[n].h = h; @@ -3680,83 +3555,73 @@ void CMapData::UpdateBuildingInfo(LPCSTR lpUnitType) CString lpPicFile = GetUnitPictureFilename(type, 0); - if (pics.find(lpPicFile) != pics.end()) - { - if (pics[lpPicFile].bTerrain == TheaterChar::None) - { + if (pics.find(lpPicFile) != pics.end()) { + if (pics[lpPicFile].bTerrain == TheaterChar::None) { buildinginfo[n].bSnow = TRUE; buildinginfo[n].bTemp = TRUE; buildinginfo[n].bUrban = TRUE; } - else if (pics[lpPicFile].bTerrain == TheaterChar::T) buildinginfo[n].bTemp = TRUE; - else if (pics[lpPicFile].bTerrain == TheaterChar::A) buildinginfo[n].bSnow = TRUE; - else if (pics[lpPicFile].bTerrain == TheaterChar::U) buildinginfo[n].bUrban = TRUE; + else if (pics[lpPicFile].bTerrain == TheaterChar::T) { + buildinginfo[n].bTemp = TRUE; + } + else if (pics[lpPicFile].bTerrain == TheaterChar::A) { + buildinginfo[n].bSnow = TRUE; + } + else if (pics[lpPicFile].bTerrain == TheaterChar::U) { + buildinginfo[n].bUrban = TRUE; + } } - else - { + else { buildinginfo[n].bSnow = TRUE; buildinginfo[n].bTemp = TRUE; buildinginfo[n].bUrban = TRUE; } buildinginfo[n].pic_count = 8; - int k; - for (k = 0;k < 8;k++) - { + for (auto k = 0;k < 8;k++) { lpPicFile = GetUnitPictureFilename(type, k); - if (pics.find(lpPicFile) != pics.end()) - { + if (pics.find(lpPicFile) != pics.end()) { buildinginfo[n].pic[k] = pics[lpPicFile]; } - else - { + else { buildinginfo[n].pic[k].pic = NULL; } } - } - else - { + } else { errstream << "Building not found " << endl; errstream.flush(); } } - for (i = 0;i < ini.sections["BuildingTypes"].values.size();i++) - { - - - CString type = *ini.sections["BuildingTypes"].GetValue(i); - CString artname = type; - - - if (ini.sections.find(type) != ini.sections.end()) - { - if (ini.sections[type].values.find("Image") != ini.sections[type].values.end()) - { - artname = ini.sections[type].values["Image"]; - } - } + for (auto const& [seq, id] : rules.GetSection("BuildingTypes")) { + auto const& type = id; + auto artname = ini.GetStringOr(type, "Image", type); int w, h; char d[6]; - memcpy(d, art.sections[artname].values["Foundation"], 1); + auto const& foundationStr = art[artname].GetString("Foundation"); + // TODO: foundationStr == "Custom" + d[0] = foundationStr[0]; d[1] = 0; w = atoi(d); - if (w == 0) w = 1; - memcpy(d, (LPCTSTR)art.sections[artname].values["Foundation"] + 2, 1); + if (w == 0) { + w = 1; + } + d[0] = foundationStr[2]; d[1] = 0; h = atoi(d); - if (h == 0) h = 1; + if (h == 0) { + h = 1; + } int n = Map->GetUnitTypeID(type); - if (n >= 0 && n < 0x0F00) - { + if (n >= 0 && n < 0x0F00) { buildinginfo[n].w = w; buildinginfo[n].h = h; buildinginfo[n].bSnow = TRUE; @@ -3766,16 +3631,13 @@ void CMapData::UpdateBuildingInfo(LPCSTR lpUnitType) CString lpPicFile = GetUnitPictureFilename(type, 0); int k; - for (k = 0;k < 8;k++) - { + for (k = 0;k < 8;k++) { lpPicFile = GetUnitPictureFilename(type, k); - if (pics.find(lpPicFile) != pics.end()) - { + if (pics.find(lpPicFile) != pics.end()) { buildinginfo[n].pic[k] = pics[lpPicFile]; } - else - { + else { buildinginfo[n].pic[k].pic = NULL; } } @@ -3783,105 +3645,81 @@ void CMapData::UpdateBuildingInfo(LPCSTR lpUnitType) } } - } - else - { - // only for specific building -> faster - CString type = lpUnitType; - CString artname = type; - - - if (rules.sections[type].values.find("Image") != rules.sections[type].values.end()) - { - artname = rules.sections[type].values["Image"]; - } - if (ini.sections.find(type) != ini.sections.end()) - { - if (ini.sections[type].values.find("Image") != ini.sections[type].values.end()) - { - artname = ini.sections[type].values["Image"]; - } - } - - int w, h; - char d[6]; - memcpy(d, art.sections[artname].values["Foundation"], 1); - d[1] = 0; - w = atoi(d); - if (w == 0) w = 1; - memcpy(d, (LPCTSTR)art.sections[artname].values["Foundation"] + 2, 1); - d[1] = 0; - h = atoi(d); - if (h == 0) h = 1; - - int n = Map->GetUnitTypeID(type); - - if (n >= 0 && n < 0x0F00) - { - buildinginfo[n].w = w; - buildinginfo[n].h = h; - CString lpPicFile = GetUnitPictureFilename(type, 0); - buildinginfo[n].pic_count = 8; - - int k; - for (k = 0;k < 8;k++) - { - lpPicFile = GetUnitPictureFilename(type, k); - - if (pics.find(lpPicFile) != pics.end()) - { - buildinginfo[n].pic[k] = pics[lpPicFile]; - } - else - { - buildinginfo[n].pic[k].pic = NULL; - } - } - - } + return; } + // only for specific building -> faster + auto const& type = *lpUnitType; + auto artname = rules.GetStringOr(type, "Image", type); + artname = ini.GetStringOr(type, "Image", artname); + + int w, h; + char d[6]; + auto const& foundationStr = art[artname].GetString("Foundation"); + // TODO: foundationStr == "Custom" + d[0] = foundationStr[0]; + d[1] = 0; + w = atoi(d); + if (w == 0) { + w = 1; + } + d[0] = foundationStr[2]; + d[1] = 0; + h = atoi(d); + if (h == 0) { + h = 1; + } + + int n = Map->GetUnitTypeID(type); + + if (n >= 0 && n < 0x0F00) { + buildinginfo[n].w = w; + buildinginfo[n].h = h; + CString lpPicFile = GetUnitPictureFilename(type, 0); + buildinginfo[n].pic_count = 8; + + int k; + for (k = 0; k < 8; k++) { + lpPicFile = GetUnitPictureFilename(type, k); + + if (pics.find(lpPicFile) != pics.end()) { + buildinginfo[n].pic[k] = pics[lpPicFile]; + } else { + buildinginfo[n].pic[k].pic = NULL; + } + } + } } -void CMapData::UpdateTreeInfo(LPCSTR lpTreeType) +void CMapData::UpdateTreeInfo(const CString* lpTreeType) { CIniFile& ini = GetIniFile(); - if (!lpTreeType) - { + if (!lpTreeType) { memset(treeinfo, 0, 0x0F00 * sizeof(TREE_INFO)); int i; - for (i = 0;i < rules.sections["TerrainTypes"].values.size();i++) - { - - - CString type = *rules.sections["TerrainTypes"].GetValue(i); - CString artname = type; - - - if (rules.sections[type].values.find("Image") != rules.sections[type].values.end()) - { - artname = rules.sections[type].values["Image"]; - } - if (ini.sections.find(type) != ini.sections.end()) - { - if (ini.sections[type].values.find("Image") != ini.sections[type].values.end()) - { - artname = ini.sections[type].values["Image"]; - } - } + for (auto const&[seq, id] : rules["TerrainTypes"]) { + auto const& type = id; + auto artname = rules.GetStringOr(type, "Image", type); + artname = ini.GetStringOr(type, "Image", artname); int w, h; char d[6]; - memcpy(d, art.sections[artname].values["Foundation"], 1); + auto const& foundationStr = art[artname].GetString("Foundation"); + // TODO: foundationStr == "Custom" + d[0] = foundationStr[0]; d[1] = 0; w = atoi(d); - if (w == 0) w = 1; - memcpy(d, (LPCTSTR)art.sections[artname].values["Foundation"] + 2, 1); + if (w == 0) { + w = 1; + } + d[0] = foundationStr[2]; d[1] = 0; h = atoi(d); - if (h == 0) h = 1; + if (h == 0) { + h = 1; + } int n = GetUnitTypeID(type); @@ -3903,32 +3741,26 @@ void CMapData::UpdateTreeInfo(LPCSTR lpTreeType) } - for (i = 0;i < ini.sections["TerrainTypes"].values.size();i++) - { - - - CString type = *ini.sections["TerrainTypes"].GetValue(i); - CString artname = type; - - - if (ini.sections.find(type) != ini.sections.end()) - { - if (ini.sections[type].values.find("Image") != ini.sections[type].values.end()) - { - artname = ini.sections[type].values["Image"]; - } - } + for (auto const& [seq, id] : ini["TerrainTypes"]) { + auto const& type = id; + auto artname = ini.GetStringOr(type, "Image", type); int w, h; char d[6]; - memcpy(d, art.sections[artname].values["Foundation"], 1); + auto const& foundationStr = art[artname].GetString("Foundation"); + // TODO: foundationStr == "Custom" + d[0] = foundationStr[0]; d[1] = 0; w = atoi(d); - if (w == 0) w = 1; - memcpy(d, (LPCTSTR)art.sections[artname].values["Foundation"] + 2, 1); + if (w == 0) { + w = 1; + } + d[0] = foundationStr[2]; d[1] = 0; h = atoi(d); - if (h == 0) h = 1; + if (h == 0) { + h = 1; + } int n = Map->GetUnitTypeID(type); @@ -3948,60 +3780,51 @@ void CMapData::UpdateTreeInfo(LPCSTR lpTreeType) } } - } - else - { - CString type = lpTreeType; - CString artname = type; - - - if (rules.sections[type].values.find("Image") != rules.sections[type].values.end()) - { - artname = rules.sections[type].values["Image"]; - } - if (ini.sections.find(type) != ini.sections.end()) - { - if (ini.sections[type].values.find("Image") != ini.sections[type].values.end()) - { - artname = ini.sections[type].values["Image"]; - } - } - - int w, h; - char d[6]; - memcpy(d, art.sections[artname].values["Foundation"], 1); - d[1] = 0; - w = atoi(d); - if (w == 0) w = 1; - memcpy(d, (LPCTSTR)art.sections[artname].values["Foundation"] + 2, 1); - d[1] = 0; - h = atoi(d); - if (h == 0) h = 1; - int n = Map->GetUnitTypeID(type); - - if (n >= 0 && n < 0x0F00) - { - treeinfo[n].w = w; - treeinfo[n].h = h; - - CString lpPicFile = GetUnitPictureFilename(type, 0); - if (pics.find(lpPicFile) != pics.end()) - { - - treeinfo[n].pic = pics[lpPicFile]; - } - else - treeinfo[n].pic.pic = NULL; - } - + return; } + auto const& type = *lpTreeType; + auto artname = rules.GetStringOr(type, "Image", type); + artname = ini.GetStringOr(type, "Image", artname); + + int w, h; + char d[6]; + auto const& foundationStr = art[artname].GetString("Foundation"); + // TODO: foundationStr == "Custom" + d[0] = foundationStr[0]; + d[1] = 0; + w = atoi(d); + if (w == 0) { + w = 1; + } + d[0] = foundationStr[2]; + d[1] = 0; + h = atoi(d); + if (h == 0) { + h = 1; + } + int n = Map->GetUnitTypeID(type); + + if (n >= 0 && n < 0x0F00) { + treeinfo[n].w = w; + treeinfo[n].h = h; + + CString lpPicFile = GetUnitPictureFilename(type, 0); + if (pics.find(lpPicFile) != pics.end()) { + treeinfo[n].pic = pics[lpPicFile]; + } else { + treeinfo[n].pic.pic = NULL; + } + } } -int CMapData::GetBuildingID(LPCSTR lpBuildingName) +int CMapData::GetBuildingID(const CString& lpBuildingName) { - if (buildingid.find(lpBuildingName) == buildingid.end()) return -1; - return buildingid[lpBuildingName]; + auto const it = buildingid.find(lpBuildingName); + if (it == buildingid.end()) { + return -1; + } + return it->second; } @@ -4025,7 +3848,9 @@ MAPFIELDDATA* CMapData::GetMappackPointer(DWORD dwPos) void CMapData::CreateMap(DWORD dwWidth, DWORD dwHeight, LPCTSTR lpTerrainType, DWORD dwGroundHeight) { - if (fielddata != NULL) delete[] fielddata; + if (fielddata != NULL) { + delete[] fielddata; + } int i; for (i = 0;i < dwSnapShotCount;i++) { @@ -4039,8 +3864,9 @@ void CMapData::CreateMap(DWORD dwWidth, DWORD dwHeight, LPCTSTR lpTerrainType, D delete[] m_snapshots[i].overlaydata; // m_snapshots[i].mapfile.Clear(); } - if (m_snapshots != NULL) delete[] m_snapshots; - + if (m_snapshots != NULL) { + delete[] m_snapshots; + } @@ -4086,7 +3912,7 @@ void CMapData::CreateMap(DWORD dwWidth, DWORD dwHeight, LPCTSTR lpTerrainType, D mapsize += ","; mapsize += c; - m_mapfile.sections["Map"].values["Size"] = mapsize; + m_mapfile.SetString("Map", "Size", mapsize); itoa(dwWidth - 4, c, 10); mapsize = "2,4,"; @@ -4095,8 +3921,8 @@ void CMapData::CreateMap(DWORD dwWidth, DWORD dwHeight, LPCTSTR lpTerrainType, D mapsize += ","; mapsize += c; - m_mapfile.sections["Map"].values["Theater"] = lpTerrainType; - m_mapfile.sections["Map"].values["LocalSize"] = mapsize; + m_mapfile.SetString("Map", "Theater", lpTerrainType); + m_mapfile.SetString("Map", "LocalSize", mapsize); map::iterator it = pics.begin(); for (int e = 0;e < pics.size();e++) @@ -4164,9 +3990,8 @@ void CMapData::CreateMap(DWORD dwWidth, DWORD dwHeight, LPCTSTR lpTerrainType, D ((CFinalSunDlg*)theApp.m_pMainWnd)->m_view.m_isoview->UpdateOverlayPictures(); theApp.m_loading->InitPics(); - - if (m_mapfile.sections["Map"].values["Theater"] == THEATER0) - { + auto const& theaterType = m_mapfile.GetString("Map", "Theater"); + if (theaterType == THEATER0) { tiledata = &s_tiledata; tiledata_count = &s_tiledata_count; tiles = &tiles_s; @@ -4199,8 +4024,7 @@ void CMapData::CreateMap(DWORD dwWidth, DWORD dwHeight, LPCTSTR lpTerrainType, D theApp.m_loading->cur_theat = 'T'; } - else if (m_mapfile.sections["Map"].values["Theater"] == THEATER1) - { + else if (theaterType == THEATER1) { tiledata = &t_tiledata; tiledata_count = &t_tiledata_count; tiles = &tiles_t; @@ -4232,8 +4056,7 @@ void CMapData::CreateMap(DWORD dwWidth, DWORD dwHeight, LPCTSTR lpTerrainType, D theApp.m_loading->InitTMPs(&dlg->m_Progress); theApp.m_loading->cur_theat = 'A'; } - else if (m_mapfile.sections["Map"].values["Theater"] == THEATER2) - { + else if (theaterType == THEATER2) { tiledata = &t_tiledata; tiledata_count = &t_tiledata_count; tiles = &tiles_t; @@ -4265,8 +4088,7 @@ void CMapData::CreateMap(DWORD dwWidth, DWORD dwHeight, LPCTSTR lpTerrainType, D theApp.m_loading->InitTMPs(&dlg->m_Progress); theApp.m_loading->cur_theat = 'U'; } - else if (yuri_mode && m_mapfile.sections["Map"].values["Theater"] == THEATER3) - { + else if (yuri_mode && theaterType == THEATER3) { tiledata = &t_tiledata; tiledata_count = &t_tiledata_count; tiles = &tiles_t; @@ -4301,8 +4123,7 @@ void CMapData::CreateMap(DWORD dwWidth, DWORD dwHeight, LPCTSTR lpTerrainType, D theApp.m_loading->InitTMPs(&dlg->m_Progress); theApp.m_loading->cur_theat = 'N'; } - else if (yuri_mode && m_mapfile.sections["Map"].values["Theater"] == THEATER4) - { + else if (yuri_mode && theaterType == THEATER4) { tiledata = &t_tiledata; tiledata_count = &t_tiledata_count; tiles = &tiles_t; @@ -4339,8 +4160,7 @@ void CMapData::CreateMap(DWORD dwWidth, DWORD dwHeight, LPCTSTR lpTerrainType, D } theApp.m_loading->cur_theat = 'L'; } - else if (m_mapfile.sections["Map"].values["Theater"] == THEATER5) - { + else if (theaterType == THEATER5) { tiledata = &t_tiledata; tiledata_count = &t_tiledata_count; tiles = &tiles_t; @@ -4376,8 +4196,7 @@ void CMapData::CreateMap(DWORD dwWidth, DWORD dwHeight, LPCTSTR lpTerrainType, D theApp.m_loading->InitTMPs(&dlg->m_Progress); theApp.m_loading->cur_theat = 'D'; } - else - { + else { theApp.m_loading->FreeAll(); CString s = "Fatal error! %9 doesn´t support the theater of this map!"; s = TranslateStringACP(s); @@ -4385,8 +4204,7 @@ void CMapData::CreateMap(DWORD dwWidth, DWORD dwHeight, LPCTSTR lpTerrainType, D exit(0); } } - else - { + else { // e.g. unittests tiles = &tiles_t; } @@ -4625,29 +4443,27 @@ DWORD CMapData::GetTileID(DWORD dwTileSet, int iTile) { int i, e; DWORD tilecount = 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++) + 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()) return 0xFFFFFFFF; - - - for (e = 0;e < atoi(tiles->sections[sec].values["TilesInSet"]);e++) - { - if (i == dwTileSet && e == iTile) return tilecount; - tilecount++; - + auto const pSec = tiles->TryGetSection(sec); + if (!pSec) { + return 0xFFFFFFFF; } - + for (e = 0; e < pSec->GetInteger("TilesInSet"); e++) { + if (i == dwTileSet && e == iTile) return tilecount; + tilecount++; + } } return tilecount; @@ -4670,30 +4486,26 @@ void CMapData::HideField(DWORD dwPos, BOOL bHide) void CMapData::UpdateTubes(BOOL bSave) { - if (!bSave) - { - m_tubes.clear(); - if (m_mapfile.sections.find("Tubes") == m_mapfile.sections.end()) - return; + if (bSave) { + return; + } - auto& tubeSection = m_mapfile.sections["Tubes"]; + m_tubes.clear(); - std::uint16_t secSize = tubeSection.values.size(); - m_tubes.reserve(secSize + 10); + auto const& tubeSection = m_mapfile["Tubes"]; + std::uint16_t secSize = tubeSection.Size(); + if (!secSize) { + return; + } + m_tubes.reserve(secSize + 10); - for (auto& [sTubeId, value] : tubeSection) - { - const auto tubeId = std::atoi(sTubeId); - if (tubeId < 0 || tubeId >= std::numeric_limits::max()) - continue; - m_tubes.push_back(std::make_unique(static_cast(tubeId), value.GetString())); + for (auto& [sTubeId, value] : tubeSection) { + const auto tubeId = std::atoi(sTubeId); + if (tubeId < 0 || tubeId >= std::numeric_limits::max()) { + continue; } + m_tubes.push_back(std::make_unique(static_cast(tubeId), value.GetString())); } - else - { - - } - } @@ -4701,47 +4513,46 @@ void CMapData::UpdateTubes(BOOL bSave) void CMapData::SetTube(CTube* lpTI) { CString sTubeId; - if (lpTI->hasId()) + if (lpTI->hasId()) { sTubeId = std::to_string(lpTI->getId()).c_str(); - else - { - for (std::uint16_t i = 0;i < 10000;i++) - { + } + else { + for (std::uint16_t i = 0;i < 10000;i++) { sTubeId = std::to_string(i).c_str(); - if (m_mapfile.sections["Tubes"].values.find(sTubeId) == m_mapfile.sections["Tubes"].values.end()) - { + if (!m_mapfile["Tubes"].Exists(sTubeId)) { lpTI->setId(i); break; } } } - if (!lpTI->hasId()) + if (!lpTI->hasId()) { return; + } - m_mapfile.sections["Tubes"].values[sTubeId] = lpTI->toString().c_str(); + m_mapfile.SetString("Tubes", sTubeId, lpTI->toString().c_str()); UpdateTubes(FALSE); } CTube* CMapData::GetTube(std::uint16_t wID) { auto it = std::find_if(m_tubes.begin(), m_tubes.end(), [wID](const auto& el) {return el->getId() == wID;}); - if (it == m_tubes.end()) + if (it == m_tubes.end()) { return nullptr; - + } return it->get(); } void CMapData::DeleteTube(std::uint16_t wID) { - if (m_mapfile.sections.find("Tubes") == m_mapfile.sections.end()) + auto pSec = m_mapfile.TryGetSection("Tubes"); + if (!pSec) { return; + } - auto& tubeSection = m_mapfile.sections["Tubes"]; const CString sTubeId = std::to_string(wID).c_str(); - - std::erase_if(tubeSection.values, [&sTubeId](const auto& el) {return el.first == sTubeId;}); + pSec->RemoveByKey(sTubeId); //CString id1 = *m_mapfile.sections["Tubes"].GetValueName(wID); @@ -5066,23 +4877,23 @@ static const CString tile_to_lat[tile_to_lat_count][3] = { bool CMapData::hasLat(WORD wGround) const { - if (wGround >= *tiledata_count) + if (wGround >= *tiledata_count) { return false; + } const auto set = (*tiledata)[wGround].wTileSet; - - const auto& sec = tiles->sections["General"]; + const auto& sec = tiles->GetSection("General"); const CString empty; - for (int i = 0; i < tile_to_lat_count; ++i) - { - const int tile = atoi(sec.GetValueByName(tile_to_lat[i][0], empty)); - const int lat = atoi(sec.GetValueByName(tile_to_lat[i][1], empty)); - const int target_tile = atoi(sec.GetValueByName(tile_to_lat[i][2], empty)); + for (int i = 0; i < tile_to_lat_count; ++i) { + const int tile = sec.GetInteger(tile_to_lat[i][0]); + const int lat = sec.GetInteger(tile_to_lat[i][1]); + const int target_tile = sec.GetInteger(tile_to_lat[i][2]); if (lat && (set == tile || set == lat || - set == target_tile)) + set == target_tile)) { return true; + } } return false; @@ -5090,28 +4901,34 @@ bool CMapData::hasLat(WORD wGround) const void CMapData::SmoothAllAt(DWORD dwPos) { - if (theApp.m_Options.bDisableAutoLat) return; + if (theApp.m_Options.bDisableAutoLat) { + return; + } - if (dwPos > fielddata_size) return; + if (dwPos > fielddata_size) { + return; + } int set = 0, ground = fielddata[dwPos].wGround; - if (ground == 0xFFFF) ground = 0; + if (ground == 0xFFFF) { + ground = 0; + } set = (*tiledata)[ground].wTileSet; - const auto& sec = tiles->sections["General"]; + const auto& sec = tiles->GetSection("General"); const CString empty; - for (int i = 0; i < tile_to_lat_count; ++i) - { - const int tile = atoi(sec.GetValueByName(tile_to_lat[i][0], empty)); - const int lat = atoi(sec.GetValueByName(tile_to_lat[i][1], empty)); - const int target_tile = atoi(sec.GetValueByName(tile_to_lat[i][2], empty)); + for (int i = 0; i < tile_to_lat_count; ++i) { + const int tile = sec.GetInteger(tile_to_lat[i][0]); + const int lat = sec.GetInteger(tile_to_lat[i][1]); + const int target_tile = sec.GetInteger(tile_to_lat[i][2]); if (strlen(tile_to_lat[i][2]) && lat && (set == tile || - set == lat)) + set == lat)) { SmoothAt(dwPos, tile, lat, target_tile); + } } } @@ -5137,12 +4954,13 @@ void CMapData::CreateShore(int left, int top, int right, int bottom, BOOL bRemov memset(noChange, 0, sizeof(BOOL) * isosize * isosize); //memset(replaced, 0, sizeof(BOOL)*isosize*isosize); - int watercliffset = atoi((*tiles).sections["General"].values["WaterCliffs"]); + int watercliffset = tiles->GetInteger("General", "WaterCliffs"); int xx, yy; - for (i = 0;i < *tiledata_count;i++) - { - if ((*tiledata)[i].wTileSet == waterset && (*tiledata)[i].cx == 1 && (*tiledata)[i].cy == 1) break; + for (i = 0; i < *tiledata_count; i++) { + if ((*tiledata)[i].wTileSet == waterset && (*tiledata)[i].cx == 1 && (*tiledata)[i].cy == 1) { + break; + } } int smallwater = i; @@ -5156,22 +4974,22 @@ void CMapData::CreateShore(int left, int top, int right, int bottom, BOOL bRemov map softsets; CString sec = "SoftTileSets"; - for (i = 0;i < g_data.sections[sec].values.size();i++) - { - CString tset = *g_data.sections[sec].GetValueName(i); + for (auto const& [key, val] : g_data[sec]) { + CString tset = key; TruncSpace(tset); - int p = (*tiles).sections["General"].FindName(tset); - if (p < 0) continue; - - int set = atoi(*(*tiles).sections["General"].GetValue(p)); - if (atoi(*g_data.sections[sec].GetValue(i))) softsets[set] = 1; + auto const& generalSec = tiles->GetSection("General"); + int idx = generalSec.FindIndex(tset); + if (idx < 0) { + continue; + } + int set = atoi(generalSec.Nth(idx).second); + if (atoi(val)) { + softsets[set] = 1; + } } - - - last_succeeded_operation = 7001; // remove partial shore pieces (wrong ones) @@ -6013,8 +5831,8 @@ void CMapData::CreateShore(int left, int top, int right, int bottom, BOOL bRemov if (bShoreFound) { - int sandtile = atoi(tiles->sections["General"].values["GreenTile"]); - int sandlat = atoi(tiles->sections["General"].values["ClearToGreenLat"]); + int sandtile = tiles->GetInteger("General", "GreenTile"); + int sandlat = tiles->GetInteger("General", "ClearToGreenLat"); int i; for (i = 0;i < *tiledata_count;i++) @@ -6058,11 +5876,11 @@ void CMapData::CreateShore(int left, int top, int right, int bottom, BOOL bRemov if (bShoreFound && hasChanged) { - int sandtile = atoi(tiles->sections["General"].values["GreenTile"]); - int sandlat = atoi(tiles->sections["General"].values["ClearToGreenLat"]); + int sandtile = tiles->GetInteger("General", "GreenTile"); + int sandlat = tiles->GetInteger("General", "ClearToGreenLat"); - SmoothAt(pos, sandtile, sandlat, atoi(tiles->sections["General"].values["ClearTile"])); + SmoothAt(pos, sandtile, sandlat, tiles->GetInteger("General", "ClearTile")); } } @@ -6087,16 +5905,22 @@ void CMapData::CreateShore(int left, int top, int right, int bottom, BOOL bRemov BOOL CMapData::IsMultiplayer() { - if (m_mapfile.sections["Basic"].FindName("Player") >= 0) return FALSE; - if (isTrue(m_mapfile.sections["Basic"].values["MultiplayerOnly"])) return TRUE; - if (m_mapfile.sections.find(MAPHOUSES) == m_mapfile.sections.end()) return TRUE; + if (m_mapfile["Basic"].Exists("Player")) { + return FALSE; + } + if (m_mapfile.GetBool("Basic", "MultiplayerOnly")) { + return TRUE; + } + if (!m_mapfile.TryGetSection(MAPHOUSES)) { + return TRUE; + } return FALSE; } CString CMapData::GetTheater() { - return m_mapfile.sections["Map"].values["Theater"]; + return m_mapfile.GetString("Map", "Theater"); } void CMapData::Copy(int left, int top, int right, int bottom) @@ -6251,7 +6075,9 @@ void CMapData::Paste(int x, int y, int z_mod) FIELDDATA* fd = Map->GetFielddataAt(i + x + (y + e) * m_IsoSize); int ground = fd->wGround; - if (ground = 0xFFFF) ground = 0; + if (ground == 0xFFFF) { + ground = 0; + } int height = fd->bHeight;//-(*tiledata)[ground].tiles[fd->bSubTile].bZHeight; @@ -6263,7 +6089,9 @@ void CMapData::Paste(int x, int y, int z_mod) } int ground = GetFielddataAt(x + y * m_IsoSize)->wGround; - if (ground == 0xFFFF) ground = 0; + if (ground == 0xFFFF) { + ground = 0; + } int startheight = lowestheight + z_mod;//-(*tiledata)[ground].tiles[GetFielddataAt(x+y*m_IsoSize)->bSubTile].bZHeight; //char c[50]; @@ -6411,22 +6239,22 @@ int CMapData::CalcMoneyOnMap() if (ovrl >= RIPARIUS_BEGIN && ovrl <= RIPARIUS_END) { - money += (ovrld + 1) * (atoi(rules.sections["Riparius"].values["Value"])); + money += (ovrld + 1) * rules.GetInteger("Riparius", "Value"); } if (ovrl >= CRUENTUS_BEGIN && ovrl <= CRUENTUS_END) { - money += (ovrld + 1) * (atoi(rules.sections["Cruentus"].values["Value"])); + money += (ovrld + 1) * rules.GetInteger("Cruentus", "Value"); } if (ovrl >= VINIFERA_BEGIN && ovrl <= VINIFERA_END) { - money += (ovrld + 1) * (atoi(rules.sections["Vinifera"].values["Value"])); + money += (ovrld + 1) * rules.GetInteger("Vinifera", "Value"); } if (ovrl >= ABOREUS_BEGIN && ovrl <= ABOREUS_END) { - money += (ovrld + 1) * (atoi(rules.sections["Aboreus"].values["Value"])); + money += (ovrld + 1) * rules.GetInteger("Aboreus", "Value"); } } @@ -6656,7 +6484,7 @@ void CMapData::ResizeMap(int iLeft, int iTop, DWORD dwNewWidth, DWORD dwNewHeigh mapsize += ","; mapsize += c; - m_mapfile.sections["Map"].values["Size"] = mapsize; + m_mapfile.SetString("Map", "Size", mapsize); itoa(dwNewWidth - 4, c, 10); mapsize = "2,4,"; @@ -6665,7 +6493,7 @@ void CMapData::ResizeMap(int iLeft, int iTop, DWORD dwNewWidth, DWORD dwNewHeigh mapsize += ","; mapsize += c; - m_mapfile.sections["Map"].values["LocalSize"] = mapsize; + m_mapfile.SetString("Map", "LocalSize", mapsize); CalcMapRect(); @@ -7000,10 +6828,8 @@ void CMapData::ResizeMap(int iLeft, int iTop, DWORD dwNewWidth, DWORD dwNewHeigh Returns TRUE for all sections that should not be modified using the INI editor, because they become modified whenever the map is saved by the editor itself. */ -BOOL CMapData::IsMapSection(LPCSTR lpSectionName) +bool CMapData::IsMapSection(const CString& str) { - CString str; - str = lpSectionName; if (str == "IsoMapPack5" || str == "OverlayPack" || str == "OverlayDataPack" || str == "Preview" || str == "PreviewPack" || str == "Map" || @@ -7014,7 +6840,7 @@ BOOL CMapData::IsMapSection(LPCSTR lpSectionName) return FALSE; } -int GetEventParamStart(CString& EventData, int param); +int GetEventParamStart(const CString& EventData, int param); BOOL CMapData::IsYRMap() { @@ -7029,14 +6855,17 @@ BOOL CMapData::IsYRMap() int i; int max = 0; - if (tiledata == &u_tiledata) - { - max = atoi(g_data.sections["RA2TileMax"].values["Urban"]); + if (tiledata == &u_tiledata) { + max = g_data.GetInteger("RA2TileMax", "Urban"); + } + else if (tiledata == &s_tiledata) { + max = g_data.GetInteger("RA2TileMax", "Snow"); + } + else if (tiledata == &t_tiledata) { + max = g_data.GetInteger("RA2TileMax", "Temperat"); } - else if (tiledata == &s_tiledata) max = atoi(g_data.sections["RA2TileMax"].values["Snow"]); - else if (tiledata == &t_tiledata) max = atoi(g_data.sections["RA2TileMax"].values["Temperat"]); - int yroverlay = atoi(g_data.sections["YROverlay"].values["Begin"]); + int yroverlay = g_data.GetInteger("YROverlay", "Begin"); for (i = 0;i < fielddata_size;i++) { @@ -7056,12 +6885,11 @@ BOOL CMapData::IsYRMap() INFANTRY inf; GetInfantryData(i, &inf); - if (inf.deleted) continue; + if (inf.deleted) { + continue; + } - CIniFileSection& sec = g_data.sections["YRInfantry"]; - - if (sec.values.find(inf.type) != sec.values.end()) - { + if (g_data["YRInfantry"].Exists(inf.type)) { return TRUE; } } @@ -7072,12 +6900,11 @@ BOOL CMapData::IsYRMap() STRUCTURE str; GetStructureData(i, &str); - if (str.deleted) continue; + if (str.deleted) { + continue; + } - CIniFileSection& sec = g_data.sections["YRBuildings"]; - - if (sec.values.find(str.type) != sec.values.end()) - { + if (g_data["YRBuildings"].Exists(str.type)) { return TRUE; } } @@ -7088,12 +6915,11 @@ BOOL CMapData::IsYRMap() UNIT unit; GetUnitData(i, &unit); - if (unit.deleted) continue; + if (unit.deleted) { + continue; + } - CIniFileSection& sec = g_data.sections["YRUnits"]; - - if (sec.values.find(unit.type) != sec.values.end()) - { + if (g_data["YRUnits"].Exists(unit.type)) { return TRUE; } } @@ -7104,12 +6930,11 @@ BOOL CMapData::IsYRMap() AIRCRAFT air; GetAircraftData(i, &air); - if (air.deleted) continue; + if (air.deleted) { + continue; + } - CIniFileSection& sec = g_data.sections["YRAircraft"]; - - if (sec.values.find(air.type) != sec.values.end()) - { + if (g_data["YRAircraft"].Exists(air.type)) { return TRUE; } } @@ -7120,51 +6945,40 @@ BOOL CMapData::IsYRMap() TERRAIN& tr = m_terrain[i]; - if (tr.deleted) continue; + if (tr.deleted) { + continue; + } - CIniFileSection& sec = g_data.sections["YRTerrain"]; - - if (sec.values.find(tr.type) != sec.values.end()) - { + if (g_data["YRTerrain"].Exists(tr.type)) { return TRUE; } } - count = m_mapfile.sections["Triggers"].values.size(); - for (i = 0;i < count;i++) - { - CString event; - CString action; - CString id; - - id = *m_mapfile.sections["Triggers"].GetValueName(i); - - event = m_mapfile.sections["Events"].values[id]; - action = m_mapfile.sections["Actions"].values[id]; + for (auto const& [id, val] : m_mapfile["Triggers"]) { + auto const& eventParams = m_mapfile.GetString("Events", id); + auto const& actionParams = m_mapfile.GetString("Actions", id); int eventcount, actioncount; - eventcount = atoi(GetParam(event, 0)); - actioncount = atoi(GetParam(action, 0)); + eventcount = atoi(GetParam(eventParams, 0)); + actioncount = atoi(GetParam(actionParams, 0)); - int e; - - for (e = 0;e < eventcount;e++) - { - CString type = GetParam(event, GetEventParamStart(event, e)); - if (g_data.sections["EventsRA2"].values.find(type) != g_data.sections["EventsRA2"].values.end()) - { - if (isTrue(GetParam(g_data.sections["EventsRA2"].values[type], 9))) + for (auto e = 0; e < eventcount; e++) { + CString type = GetParam(eventParams, GetEventParamStart(eventParams, e)); + auto const& eventDetail = g_data.GetString("EventsRA2", type); + if (!eventDetail.IsEmpty()) { + if (isTrue(GetParam(eventDetail, 9))) { return TRUE; + } } } - for (e = 0;e < actioncount;e++) - { - CString type = GetParam(action, 1 + e * 8); - if (g_data.sections["ActionsRA2"].values.find(type) != g_data.sections["ActionsRA2"].values.end()) - { - if (isTrue(GetParam(g_data.sections["ActionsRA2"].values[type], 14))) + for (auto e = 0; e < actioncount; e++) { + CString type = GetParam(actionParams, 1 + e * 8); + auto const& actionDetail = g_data.GetString("ActionsRA2", type); + if (!actionDetail.IsEmpty()) { + if (isTrue(GetParam(actionDetail, 14))) { return TRUE; + } } } } @@ -7239,185 +7053,143 @@ void CMapData::DeleteSmudge(DWORD dwIndex) void CMapData::UpdateSmudges(BOOL bSave, int num) { - vector& t = m_smudges; + vector& smudges = m_smudges; - if (bSave == FALSE) - { - if (m_mapfile.sections.find("Smudge") == m_mapfile.sections.end() || m_mapfile.sections["Smudge"].values.size() <= 0) + if (bSave == FALSE) { + auto const& sec = m_mapfile.GetSection("Smudge"); + if (sec.Size() <= 0) { return; + } - if (num < 0) - { - t.clear(); - t.reserve(100); + if (num < 0) { + smudges.clear(); + smudges.reserve(100); - int i; - for (i = 0;i < GetIsoSize() * GetIsoSize();i++) - { + for (auto i = 0; i < GetIsoSize() * GetIsoSize(); i++) { fielddata[i].smudge = -1; } - - - CIniFileSection& sec = m_mapfile.sections["Smudge"]; - - for (i = 0;i < sec.values.size();i++) - { + for (auto i = 0; i < sec.Size(); i++) { int x, y; - x = atoi(GetParam(*sec.GetValue(i), 2)); - y = atoi(GetParam(*sec.GetValue(i), 1)); + auto const& val = sec.Nth(i).second; + x = atoi(GetParam(val, 2)); + y = atoi(GetParam(val, 1)); // check for valid coordinates ; MW May 17th 2001 ASSERT(x >= 0 && x < GetIsoSize()); ASSERT(y >= 0 && y < GetIsoSize()); - if (x < 0 || x >= GetIsoSize() || y < 0 || y >= GetIsoSize()) - { + if (x < 0 || x >= GetIsoSize() || y < 0 || y >= GetIsoSize()) { // invalid coordinates - ignore in release + continue; } - else - { - SMUDGE td; - td.deleted = 0; - td.type = GetParam(*sec.GetValue(i), 0); - td.x = x; - td.y = y; - t.push_back(td); + SMUDGE td; + td.deleted = 0; + td.type = GetParam(val, 0); + td.x = x; + td.y = y; - int pos = x + y * GetIsoSize(); - fielddata[pos].smudge = i; - fielddata[pos].smudgetype = smudgeid[td.type]; - } + smudges.push_back(td); + + int pos = x + y * GetIsoSize(); + fielddata[pos].smudge = i; + fielddata[pos].smudgetype = smudgeid[td.type]; } - m_mapfile.sections.erase("Smudge"); + m_mapfile.DeleteSection("Smudge"); } - + return; } - else + + + + //if(num<0) { + //if(m_mapfile.sections.find("Smudge")!=m_mapfile.sections.end()) MessageBox(0,"Reupdate!","",0); + m_mapfile.DeleteSection("Smudge"); + int i; - //if(num<0) - { - //if(m_mapfile.sections.find("Smudge")!=m_mapfile.sections.end()) MessageBox(0,"Reupdate!","",0); - m_mapfile.sections.erase("Smudge"); - int i; + for (i = 0; i < smudges.size(); i++) { + auto const& td = smudges[i]; + if (!td.deleted) { + char numBuffer[50]; + CString val = td.type; + val += ","; + itoa(td.y, numBuffer, 10); + val += numBuffer; + val += ","; + itoa(td.x, numBuffer, 10); + val += numBuffer; + val += ",0"; - for (i = 0;i < t.size();i++) - { - SMUDGE& td = t[i]; - if (!td.deleted) - { - char c[50]; - CString val = td.type; - val += ","; - itoa(td.y, c, 10); - val += c; - val += ","; - itoa(td.x, c, 10); - val += c; - val += ",0"; + itoa(i, numBuffer, 10); - itoa(i, c, 10); - - m_mapfile.sections["Smudge"].values[c] = val; - } + m_mapfile.SetString("Smudge", numBuffer, val); } } - } - } void CMapData::UpdateSmudgeInfo(LPCSTR lpSmudgeType) { CIniFile& ini = GetIniFile(); - if (!lpSmudgeType) - { + if (!lpSmudgeType) { memset(smudgeinfo, 0, 0x0F00 * sizeof(SMUDGE_INFO)); int i; - for (i = 0;i < rules.sections["SmudgeTypes"].values.size();i++) - { - - - CString type = *rules.sections["SmudgeTypes"].GetValue(i); - CString artname = type; - - + for (auto const& [seq, type] : rules.GetSection("SmudgeTypes")) { int n = GetUnitTypeID(type); - if (n >= 0 && n < 0x0F00) - { - + if (n >= 0 && n < 0x0F00) { CString lpPicFile = GetUnitPictureFilename(type, 0); - if (pics.find(lpPicFile) != pics.end()) - { - + if (pics.find(lpPicFile) != pics.end()) { smudgeinfo[n].pic = pics[lpPicFile]; } - else + else { smudgeinfo[n].pic.pic = NULL; + } } } - for (i = 0;i < ini.sections["SmudgeTypes"].values.size();i++) - { - - - CString type = *ini.sections["SmudgeTypes"].GetValue(i); - CString artname = type; - - - + for (auto const&[seq, type]: ini.GetSection("SmudgeTypes")) { int n = Map->GetUnitTypeID(type); - if (n >= 0 && n < 0x0F00) - { + if (n >= 0 && n < 0x0F00) { //smudgeinfo[n].w=w; //smudgeinfo[n].h=h; CString lpPicFile = GetUnitPictureFilename(type, 0); - if (pics.find(lpPicFile) != pics.end()) - { + if (pics.find(lpPicFile) != pics.end()) { smudgeinfo[n].pic = pics[lpPicFile]; } - else + else { smudgeinfo[n].pic.pic = NULL; + } } } + return; } - else - { - CString type = lpSmudgeType; - CString artname = type; + CString type = lpSmudgeType; + CString artname = type; + int n = Map->GetUnitTypeID(type); - int n = Map->GetUnitTypeID(type); + if (n >= 0 && n < 0x0F00) { + CString lpPicFile = GetUnitPictureFilename(type, 0); + if (pics.find(lpPicFile) != pics.end()) { - if (n >= 0 && n < 0x0F00) - { - - CString lpPicFile = GetUnitPictureFilename(type, 0); - if (pics.find(lpPicFile) != pics.end()) - { - - smudgeinfo[n].pic = pics[lpPicFile]; - } - else - smudgeinfo[n].pic.pic = NULL; + smudgeinfo[n].pic = pics[lpPicFile]; + } else { + smudgeinfo[n].pic.pic = NULL; } - } - - } void CMapData::GetSmudgeData(DWORD dwIndex, SMUDGE* lpData) const diff --git a/MissionEditor/MapData.h b/MissionEditor/MapData.h index 2ae8f86..63f06ba 100644 --- a/MissionEditor/MapData.h +++ b/MissionEditor/MapData.h @@ -316,7 +316,7 @@ public: int rampbase = rampset_start;//atoi((*tiles).sections["General"].values["RampBase"]); - int rampsmooth = atoi((*tiles).sections["General"].AccessValueByName("RampSmooth")); + int rampsmooth = tiles->GetInteger("General", "RampSmooth"); if (ns == -1 && (d.wTileSet == rampset || d.wTileSet == rampsmooth) && d.bMorphable) { @@ -360,8 +360,7 @@ public: if (dwPos > fielddata_size) return FALSE; int replacement = 0; // MW fix: ignore for bridges - if ((*tiledata)[dwID].bReplacementCount && atoi((*tiles).sections["General"].AccessValueByName("BridgeSet")) != (*tiledata)[dwID].wTileSet) - { + if ((*tiledata)[dwID].bReplacementCount && tiles->GetInteger("General", "BridgeSet") != (*tiledata)[dwID].wTileSet) { replacement = rand() * (1 + (*tiledata)[dwID].bReplacementCount) / RAND_MAX; } @@ -400,7 +399,7 @@ public: } - int GetBuildingID(LPCSTR lpBuildingName); + int GetBuildingID(const CString& lpBuildingName); void ImportRUL(LPCTSTR lpFilename); void ExportRulesChanges(const char* filename); void DeleteRulesSections(); @@ -609,8 +608,8 @@ public: virtual ~CMapData(); void Pack(BOOL bCreatePreview = FALSE, BOOL bCompression = FALSE); void Unpack(); - void UpdateTreeInfo(LPCSTR lpTreeType = NULL); - void UpdateBuildingInfo(LPCSTR lpUnitType = NULL); + void UpdateTreeInfo(const CString* lpTreeType = NULL); + void UpdateBuildingInfo(const CString* lpUnitType = NULL); void CalcMapRect(); // MW change: UpdateStructures() public, so that houses dialog can access it @@ -1000,7 +999,7 @@ public: #endif BOOL IsYRMap(); - BOOL IsMapSection(LPCSTR lpSectionName); + bool IsMapSection(const CString& sectionName); void ResizeMap(int iLeft, int iTop, DWORD dwNewWidth, DWORD dwNewHeight); void SmoothTiberium(DWORD dwPos); int GetPowerOfHouse(LPCTSTR lpHouse); diff --git a/MissionEditor/MapOpenDialog.cpp b/MissionEditor/MapOpenDialog.cpp index 25eca84..a2aa0f1 100644 --- a/MissionEditor/MapOpenDialog.cpp +++ b/MissionEditor/MapOpenDialog.cpp @@ -35,7 +35,7 @@ static char THIS_FILE[] = __FILE__; ///////////////////////////////////////////////////////////////////////////// // CMapOpenDialog -UINT CALLBACK OFNHookProc( +UINT_PTR CALLBACK OFNHookProc( HWND hdlg, // handle to child dialog window UINT uiMsg, // message identifier WPARAM wParam, // message parameter @@ -56,7 +56,7 @@ UINT CALLBACK OFNHookProc( CIniFile CurMap; CurMap.InsertFile(utf16ToUtf8(psz),"Basic"); - SetDlgItemText(hdlg, IDC_MAPNAME, CurMap.sections["Basic"].values["Name"]); + SetDlgItemText(hdlg, IDC_MAPNAME, CurMap.GetString("Basic", "Name")); } diff --git a/MissionEditor/MapValidator.cpp b/MissionEditor/MapValidator.cpp index fbf4ec2..47ec824 100644 --- a/MissionEditor/MapValidator.cpp +++ b/MissionEditor/MapValidator.cpp @@ -132,36 +132,30 @@ BOOL CMapValidator::CheckMap() Map->UpdateIniFile(MAPDATA_UPDATE_TO_INI); CIniFile& ini=Map->GetIniFile(); - if(ini.sections.find("Map")==ini.sections.end() ) - { - bAllow=FALSE; + if (!ini.TryGetSection("Map")) { + bAllow = FALSE; AddItemWithNewLine(m_MapProblemList, GetLanguageStringACP("MV_NoMap"), 0); } - if(ini.sections.find("Basic")==ini.sections.end() || ini.sections["Basic"].values.size()==0) - { - bAllow=FALSE; + if (ini["Basic"].Size() == 0) { + bAllow = FALSE; AddItemWithNewLine(m_MapProblemList, GetLanguageStringACP("MV_NoBasic"), 0); - - } - else - { - if(ini.sections["Basic"].values["Name"].GetLength()==0) + } else { + if (ini.GetString("Basic","Name").IsEmpty()) { AddItemWithNewLine(m_MapProblemList, GetLanguageStringACP("MV_NoName"), 1); + } - if(ini.sections["Basic"].values.find("Player")==ini.sections["Basic"].values.end()) - { #ifdef TS_MODE + if (ini.GetString("Basic", "Player").IsEmpty()) { if(ini.sections.find(MAPHOUSES)!=ini.sections.end() && ini.sections["Houses"].values.size()>0) { AddItemWithNewLine(m_MapProblemList, GetLanguageStringACP("MV_HousesButNoPlayer"), 1); AddItemWithNewLine(m_MapProblemList, GetLanguageStringACP("MV_HousesInMultiplayer"), 1); } -#endif } - - if(ini.sections.find(MAPHOUSES)==ini.sections.end()) - { - int d=Map->GetWaypointCount(); +#endif + + if (!ini.TryGetSection(MAPHOUSES)) { + int d = Map->GetWaypointCount(); int below8found=0; int i; for(i=0;i0 && ini.sections["TaskForces"].FindValue(taskforce)<0) - { - CString error; - error=GetLanguageStringACP("MV_TaskForceMissing"); - error=TranslateStringVariables(1, error, taskforce); - error=TranslateStringVariables(2, error, *ini.sections["TeamTypes"].GetValue(i)); - AddItemWithNewLine(m_MapProblemList, error, 1); - } - } - for(i=0;i0 && ini.sections["ScriptTypes"].FindValue(scripttype)<0) - { - CString error; - error=GetLanguageStringACP("MV_ScripttypeMissing"); - error=TranslateStringVariables(1, error, scripttype); - error=TranslateStringVariables(2, error, *ini.sections["TeamTypes"].GetValue(i)); - AddItemWithNewLine(m_MapProblemList, error, 1); - } - } - for(i=0;i=0) - { - CString tag=sec.values["Tag"]; - if(ini.sections["Tags"].FindName(tag)<0) - { + if (auto pTriggerSec = ini.TryGetSection("Triggers")) { + for (auto& [id, def] : *pTriggerSec) { + auto defCopy = def; + if (RepairTrigger(defCopy)) { + pTriggerSec->SetString(id, defCopy); + } + // check linked trigger + auto const trigger = GetParam(defCopy, 1); + if (!pTriggerSec->Exists(trigger) && trigger != "") { CString error; - error=GetLanguageStringACP("MV_TagMissing"); - error=TranslateStringVariables(1, error, tag); - error=TranslateStringVariables(2, error, "Teamtype"); - error=TranslateStringVariables(3, error, *ini.sections["TeamTypes"].GetValue(i)); + error = GetLanguageStringACP("MV_TriggerMissing"); + error = TranslateStringVariables(1, error, trigger); + error = TranslateStringVariables(2, error, "Trigger"); + error = TranslateStringVariables(3, error, id); AddItemWithNewLine(m_MapProblemList, error, 1); } } } - for(i=0;iGetCelltagCount();i++) - { + + for (auto const& [seq, id] : ini["TeamTypes"]) { + auto const& sec = ini[id]; + // check taskforce + auto const taskforce = sec.GetString("TaskForce"); + if (!taskforce.IsEmpty() && !ini["TaskForces"].HasValue(taskforce)) { + CString error; + error = GetLanguageStringACP("MV_TaskForceMissing"); + error = TranslateStringVariables(1, error, taskforce); + error = TranslateStringVariables(2, error, id); + AddItemWithNewLine(m_MapProblemList, error, 1); + } + // check script + CString scripttype = sec.GetString("Script"); + if (!scripttype.IsEmpty() && !ini["ScriptTypes"].HasValue(scripttype)) { + CString error; + error = GetLanguageStringACP("MV_ScripttypeMissing"); + error = TranslateStringVariables(1, error, scripttype); + error = TranslateStringVariables(2, error, id); + AddItemWithNewLine(m_MapProblemList, error, 1); + } + // check tag + auto const& tag = sec.GetString("Tag"); + if (!tag.IsEmpty()) { + if (!ini["Tags"].Exists(tag)) { + CString error; + error = GetLanguageStringACP("MV_TagMissing"); + error = TranslateStringVariables(1, error, tag); + error = TranslateStringVariables(2, error, "Teamtype"); + error = TranslateStringVariables(3, error, id); + AddItemWithNewLine(m_MapProblemList, error, 1); + } + } + } + + for (auto i = 0; i < Map->GetCelltagCount(); i++) { CString tag; DWORD pos; Map->GetCelltagData(i, &tag, &pos); @@ -283,8 +265,7 @@ BOOL CMapValidator::CheckMap() CString p=cx; p+="/"; p+=cy; - if(ini.sections["Tags"].FindName(tag)<0) - { + if (!ini["Tags"].Exists(tag)) { CString error; error=GetLanguageStringACP("MV_TagMissing"); error=TranslateStringVariables(1, error, tag); diff --git a/MissionEditor/MissionEditor.vcxproj b/MissionEditor/MissionEditor.vcxproj index 825ae6e..79bd618 100644 --- a/MissionEditor/MissionEditor.vcxproj +++ b/MissionEditor/MissionEditor.vcxproj @@ -1,6 +1,22 @@  + + FinalAlertDebug YR + x64 + + + FinalAlertDebug + x64 + + + FinalAlertRelease YR + x64 + + + FinalAlertRelease + x64 + FinalSunDebug Win32 @@ -21,18 +37,34 @@ FinalAlertRelease Win32 + + FinalSunDebug + x64 + FinalSunRelease Win32 + + FinalSunRelease + x64 + Template Win32 + + Template + x64 + Tests FinalAlertDebug YR Win32 + + Tests FinalAlertDebug YR + x64 + MissionEditor @@ -50,54 +82,103 @@ Application v143 + + Application + v143 + Application v143 Dynamic MultiByte + + Application + v143 + Dynamic + MultiByte + Application v143 Dynamic MultiByte + + Application + v143 + Dynamic + MultiByte + Application v143 Dynamic MultiByte + + Application + v143 + Dynamic + MultiByte + Application v143 Dynamic MultiByte + + Application + v143 + Dynamic + MultiByte + Application v143 Dynamic MultiByte + + Application + v143 + Dynamic + MultiByte + Application v143 Dynamic MultiByte + + Application + v143 + Dynamic + MultiByte + Application v143 Dynamic MultiByte + + Application + v143 + Dynamic + MultiByte + + + + @@ -105,6 +186,13 @@ + + + + + + + @@ -112,6 +200,13 @@ + + + + + + + @@ -119,6 +214,13 @@ + + + + + + + @@ -126,6 +228,13 @@ + + + + + + + @@ -133,6 +242,13 @@ + + + + + + + @@ -140,6 +256,13 @@ + + + + + + + @@ -148,35 +271,71 @@ + + + + + + + + true FinalAlert2YR_D + + true + FinalAlert2YR_D + true FinalAlert2YRTestsd + + true + FinalAlert2YRTestsd + true FinalAlert2_D + + true + FinalAlert2_D + false FinalAlert2 + + false + FinalAlert2 + false FinalAlert2YR + + false + FinalAlert2YR + true FinalSun_D + + true + FinalSun_D + false FinalSun + + false + FinalSun + RA2_MODE;YR_MODE;%(PreprocessorDefinitions) @@ -186,6 +345,15 @@ RA2_MODE;YR_MODE;%(PreprocessorDefinitions) + + + RA2_MODE;YR_MODE;%(PreprocessorDefinitions) + ..\MissionEditorPackLib + + + RA2_MODE;YR_MODE;%(PreprocessorDefinitions) + + RA2_MODE;YR_MODE;%(PreprocessorDefinitions) @@ -195,6 +363,15 @@ RA2_MODE;YR_MODE;%(PreprocessorDefinitions) + + + RA2_MODE;YR_MODE;%(PreprocessorDefinitions) + ..\MissionEditorPackLib + + + RA2_MODE;YR_MODE;%(PreprocessorDefinitions) + + RA2_MODE;%(PreprocessorDefinitions) @@ -204,6 +381,15 @@ RA2_MODE;RA2_MODE_ICON;%(PreprocessorDefinitions) + + + RA2_MODE;%(PreprocessorDefinitions) + ..\MissionEditorPackLib + + + RA2_MODE;RA2_MODE_ICON;%(PreprocessorDefinitions) + + RA2_MODE;%(PreprocessorDefinitions) @@ -213,6 +399,15 @@ RA2_MODE;RA2_MODE_ICON;%(PreprocessorDefinitions) + + + RA2_MODE;%(PreprocessorDefinitions) + ..\MissionEditorPackLib + + + RA2_MODE;RA2_MODE_ICON;%(PreprocessorDefinitions) + + RA2_MODE;YR_MODE;%(PreprocessorDefinitions) @@ -222,6 +417,15 @@ RA2_MODE;YR_MODE;%(PreprocessorDefinitions) + + + RA2_MODE;YR_MODE;%(PreprocessorDefinitions) + ..\MissionEditorPackLib + + + RA2_MODE;YR_MODE;%(PreprocessorDefinitions) + + TS_MODE;%(PreprocessorDefinitions) @@ -231,6 +435,15 @@ TS_MODE;%(PreprocessorDefinitions) + + + TS_MODE;%(PreprocessorDefinitions) + ..\MissionEditorPackLib + + + TS_MODE;%(PreprocessorDefinitions) + + TS_MODE;%(PreprocessorDefinitions) @@ -240,11 +453,25 @@ TS_MODE;%(PreprocessorDefinitions) + + + TS_MODE;%(PreprocessorDefinitions) + ..\MissionEditorPackLib + + + TS_MODE;%(PreprocessorDefinitions) + + ..\MissionEditorPackLib + + + ..\MissionEditorPackLib + + @@ -306,19 +533,33 @@ Create + Create Create + Create stdafx.h + stdafx.h stdafx.h + stdafx.h Create + Create stdafx.h + stdafx.h Create + Create stdafx.h + stdafx.h Create + Create stdafx.h + stdafx.h Create + Create stdafx.h + stdafx.h Create + Create stdafx.h + stdafx.h @@ -367,6 +608,7 @@ + diff --git a/MissionEditor/MissionEditor.vcxproj.filters b/MissionEditor/MissionEditor.vcxproj.filters index 0f0da59..d54b83f 100644 --- a/MissionEditor/MissionEditor.vcxproj.filters +++ b/MissionEditor/MissionEditor.vcxproj.filters @@ -565,6 +565,9 @@ Header Files + + Header Files + diff --git a/MissionEditor/NewMap.cpp b/MissionEditor/NewMap.cpp index c7b9e2d..7ba9409 100644 --- a/MissionEditor/NewMap.cpp +++ b/MissionEditor/NewMap.cpp @@ -118,14 +118,13 @@ BOOL CNewMap::OnInitDialog() CComboBox& house=*((CComboBox*)(GetDlgItem(IDC_HOUSE))); int i; - for(i=0;iAddString(TranslateHouse(*rules.sections[HOUSES].GetValue(i), TRUE)); + for (auto const& [seq, id] : rules[HOUSES]) { + country->AddString(TranslateHouse(id, TRUE)); } country->SetCurSel(0); diff --git a/MissionEditor/PropertySheets/Debug.props b/MissionEditor/PropertySheets/Debug.props index fac5737..3f12aa6 100644 --- a/MissionEditor/PropertySheets/Debug.props +++ b/MissionEditor/PropertySheets/Debug.props @@ -4,7 +4,7 @@ - $(XccDir)\vcpkg_installed\x86-windows\x86-windows + $(XccDir)\vcpkg_installed\$(Platform)-windows\$(Platform)-windows $(XccVcpkgDirTriplet)\debug diff --git a/MissionEditor/PropertySheets/Release.props b/MissionEditor/PropertySheets/Release.props index 0e155dc..6f1c942 100644 --- a/MissionEditor/PropertySheets/Release.props +++ b/MissionEditor/PropertySheets/Release.props @@ -4,7 +4,7 @@ - $(XccDir)\vcpkg_installed\x86-windows\x86-windows + $(XccDir)\vcpkg_installed\$(Platform)-windows\$(Platform)-windows $(XccVcpkgDirTriplet) diff --git a/MissionEditor/RTPDlg.cpp b/MissionEditor/RTPDlg.cpp index 84dbf0b..71e24ed 100644 --- a/MissionEditor/RTPDlg.cpp +++ b/MissionEditor/RTPDlg.cpp @@ -76,32 +76,29 @@ BOOL CRTPDlg::OnInitDialog() { CDialog::OnInitDialog(); - int i; - for(i=0;i=0) continue; - + if (g_data["IgnoreRA2"].HasValue(unitname)) { + continue; + } addedString=TranslateStringACP(addedString); - - if(unitname.Find("TREE")>=0) - { - - + if (unitname.Find("TREE") >= 0) { if(unitname.GetLength()>0 && unitname!="VEINTREE") // out with it :-) { - int TreeMin=atoi(g_data.sections[Map->GetTheater()+"Limits"].values["TreeMin"]); - int TreeMax=atoi(g_data.sections[Map->GetTheater()+"Limits"].values["TreeMax"]); + auto const& theaterType = Map->GetTheater(); + int TreeMin = g_data.GetInteger(theaterType + "Limits", "TreeMin"); + int TreeMax = g_data.GetInteger(theaterType + "Limits", "TreeMax"); CString id=unitname; id.Delete(0, 4); int n=atoi(id); - if(nTreeMax) continue; + if (nTreeMax) { + continue; + } m_Available.AddString(unitname); } @@ -237,7 +234,7 @@ void CRTPDlg::OnPaint() if(missingimages.find(type)==missingimages.end()) { theApp.m_loading->LoadUnitGraphic(type); - Map->UpdateTreeInfo(type); + Map->UpdateTreeInfo(&type); p=&treeinfo[id].pic; } if(p->pic==NULL) diff --git a/MissionEditor/SaveMapOptionsDlg.cpp b/MissionEditor/SaveMapOptionsDlg.cpp index c420601..e955f52 100644 --- a/MissionEditor/SaveMapOptionsDlg.cpp +++ b/MissionEditor/SaveMapOptionsDlg.cpp @@ -59,7 +59,7 @@ CSaveMapOptionsDlg::CSaveMapOptionsDlg(CWnd* pParent /*=NULL*/) if(!Map->IsMultiplayer()) m_PreviewMode=1; - m_MapName=ini.sections["Basic"].values["Name"]; + m_MapName = ini.GetString("Basic", "Name"); } diff --git a/MissionEditor/ScriptTypes.cpp b/MissionEditor/ScriptTypes.cpp index 3e9a76b..5964a04 100644 --- a/MissionEditor/ScriptTypes.cpp +++ b/MissionEditor/ScriptTypes.cpp @@ -316,21 +316,18 @@ void CScriptTypes::UpdateDialog() UpdateData(FALSE); - - int i; - for(i=0;i=0) m_ScriptType.SetCurSel(sel); + if (sel >= 0) { + m_ScriptType.SetCurSel(sel); + } OnSelchangeScripttype(); @@ -353,12 +350,11 @@ void CScriptTypes::OnSelchangeScripttype() m_ScriptType.GetLBText(m_ScriptType.GetCurSel(), Scripttype); TruncSpace(Scripttype); - m_Name=ini.sections[(LPCTSTR)Scripttype].values["Name"]; + m_Name = ini.GetString(Scripttype, "Name"); - int count=ini.sections[(LPCTSTR)Scripttype].values.size()-1; + int count = ini[Scripttype].Size() - 1; int i; - for(i=0;iGetIniFile(); + CIniFile& ini = Map->GetIniFile(); CString Scripttype; char action[50]; - if(m_ScriptType.GetCurSel()<0) return; - if(m_Action.GetCurSel()<0) return; + if (m_ScriptType.GetCurSel() < 0) { + return; + } + if (m_Action.GetCurSel() < 0) { + return; + } m_ScriptType.GetLBText(m_ScriptType.GetCurSel(), Scripttype); TruncSpace(Scripttype); itoa(m_Action.GetCurSel(), action, 10); //m_Type.SetWindowText(GetParam(ini.sections[(LPCTSTR)Scripttype].values[action],0)); - m_Type.SetCurSel(atoi(GetParam(ini.sections[(LPCTSTR)Scripttype].values[action], 0))); + m_Type.SetCurSel(atoi(GetParam(ini.GetString(Scripttype, action), 0))); OnSelchangeType(); - m_Param.SetWindowText(GetParam(ini.sections[(LPCTSTR)Scripttype].values[action],1)); + m_Param.SetWindowText(GetParam(ini.GetString(Scripttype, action), 1)); } @@ -404,13 +404,15 @@ void CScriptTypes::OnChangeName() DWORD pos=n->GetSel(); CString Scripttype; - if(m_ScriptType.GetCurSel()<0) return; + if (m_ScriptType.GetCurSel() < 0) { + return; + } m_ScriptType.GetLBText(m_ScriptType.GetCurSel(), Scripttype); TruncSpace(Scripttype); - ini.sections[(LPCTSTR)Scripttype].values["Name"]=m_Name; + ini.SetString(Scripttype, "Name", m_Name); UpdateDialog(); n->SetSel(pos); @@ -466,8 +468,9 @@ void CScriptTypes::OnEditchangeType() case 6: m_Desc.SetWindowText("Script action #:"); while(m_Param.DeleteString(0)!=CB_ERR); - for(i=1;i<=ini.sections[(LPCTSTR)Scripttype].values.size()-1;i++) - m_Param.AddString(itoa(i,tmp,10)); + for (i = 1; i <= ini[Scripttype].Size() - 1; i++) { + m_Param.AddString(itoa(i, tmp, 10)); + } break; case 8: m_Desc.SetWindowText("Split groups:"); @@ -501,19 +504,17 @@ void CScriptTypes::OnEditchangeType() case 47: { m_Desc.SetWindowText("Type to move/attack:"); - - for(i=0;iGetUnitName(*rules.sections["BuildingTypes"].GetValue(i)); + s+=Map->GetUnitName(bldTypeSec.Nth(i).second); m_Param.AddString(s); } - break; } @@ -525,10 +526,7 @@ void CScriptTypes::OnEditchangeType() char types[50]; itoa(type, types, 10); - ini.sections[(LPCTSTR)Scripttype].values[action]=SetParam(ini.sections[(LPCTSTR)Scripttype].values[action], 0, (LPCTSTR)types); - - - + ini.SetString(Scripttype, action, SetParam(ini.GetString(Scripttype, action), 0, types)); } void CScriptTypes::OnSelchangeType() @@ -565,9 +563,7 @@ void CScriptTypes::OnEditchangeParam() param=TranslateHouse(param); itoa(m_Action.GetCurSel(), action, 10); - ini.sections[(LPCTSTR)Scripttype].values[action]=SetParam(ini.sections[(LPCTSTR)Scripttype].values[action], 1, (LPCTSTR)param); - - + ini.SetString(Scripttype, action, SetParam(ini.GetString(Scripttype, action), 1, param)); } void CScriptTypes::OnSelchangeParam() @@ -587,9 +583,9 @@ void CScriptTypes::OnAddaction() char action[20]; - int count=ini.sections[(LPCTSTR)Scripttype].values.size()-1; + int count = ini[Scripttype].Size() - 1; itoa(count,action,10); - ini.sections[(LPCTSTR)Scripttype].values[action]="0,0"; + ini.SetString(Scripttype, action, "0,0"); UpdateDialog(); } @@ -616,11 +612,11 @@ void CScriptTypes::OnDeleteaction() itoa(i, current, 10); itoa(i+1, next, 10); - ini.sections[(LPCTSTR)Scripttype].values[current]=ini.sections[(LPCTSTR)Scripttype].values[next]; + ini.SetString(Scripttype, current, ini.GetString(Scripttype, next)); } char last[50]; itoa(m_Action.GetCount()-1, last, 10); - ini.sections[(LPCTSTR)Scripttype].values.erase(last); + ini.RemoveValueByKey(Scripttype, last); UpdateDialog(); } @@ -634,8 +630,8 @@ void CScriptTypes::OnAdd() CString ID=GetFreeID(); CString p=GetFree("ScriptTypes"); - ini.sections["ScriptTypes"].values[p]=ID; - ini.sections[ID].values["Name"]="New script"; + ini.SetString("ScriptTypes", p, ID); + ini.SetString(ID, "Name", "New script"); @@ -668,10 +664,13 @@ void CScriptTypes::OnDelete() TruncSpace(Scripttype); int res=MessageBox("Are you sure to delete this ScriptType? Don´t forget to delete any references to this ScriptType","Delete ScriptType", MB_YESNO | MB_ICONQUESTION); - if(res!=IDYES) return; + if (res != IDYES) { + return; + } - ini.sections.erase((LPCTSTR)Scripttype); - ini.sections["ScriptTypes"].values.erase(*ini.sections["ScriptTypes"].GetValueName(ini.sections["ScriptTypes"].FindValue((LPCTSTR)Scripttype))); + ini.DeleteSection(Scripttype); + auto const& id = ini["ScriptTypes"].Nth(ini["ScriptTypes"].FindValue(Scripttype)).first; + ini.RemoveValueByKey("ScriptTypes", id); //UpdateDialog(); ((CFinalSunDlg*)theApp.m_pMainWnd)->UpdateDialogs(TRUE); } diff --git a/MissionEditor/SingleplayerSettings.cpp b/MissionEditor/SingleplayerSettings.cpp index 9a1c67c..24d34d4 100644 --- a/MissionEditor/SingleplayerSettings.cpp +++ b/MissionEditor/SingleplayerSettings.cpp @@ -92,31 +92,26 @@ void CSingleplayerSettings::UpdateDialog() { CIniFile& ini=Map->GetIniFile(); - CIniFileSection& sec=ini.sections["Basic"]; + auto const& sec = ini["Basic"]; - if(sec.values.find("Intro")!=sec.values.end()) - m_Intro.SetWindowText(sec.values["Intro"]); - if(sec.values.find("Brief")!=sec.values.end()) - m_Brief.SetWindowText(sec.values["Brief"]); - if(sec.values.find("Win")!=sec.values.end()) - m_Win.SetWindowText(sec.values["Win"]); - if(sec.values.find("Lose")!=sec.values.end()) - m_Lose.SetWindowText(sec.values["Lose"]); - if(sec.values.find("Action")!=sec.values.end()) - m_Action.SetWindowText(sec.values["Action"]); - if(sec.values.find("PostScore")!=sec.values.end()) - m_PostScore.SetWindowText(sec.values["PostScore"]); - if(sec.values.find("PreMapSelect")!=sec.values.end()) - m_PreMapSelect.SetWindowText(sec.values["PreMapSelect"]); + auto setIfExists = [&sec](CWnd& wnd, const CString& key) { + if (auto val = sec.TryGetString(key)) { + wnd.SetWindowText(*val); + } + }; - if(sec.values.find("StartingDropships")!=sec.values.end()) - m_StartingDropships.SetWindowText(sec.values["StartingDropships"]); - if(sec.values.find("CarryOverMoney")!=sec.values.end()) - m_CarryOverMoney.SetWindowText(sec.values["CarryOverMoney"]); - if(sec.values.find("TimerInherit")!=sec.values.end()) - m_TimerInherit.SetWindowText(sec.values["TimerInherit"]); - if(sec.values.find("FillSilos")!=sec.values.end()) - m_FillSilos.SetWindowText(sec.values["FillSilos"]); + setIfExists(m_Intro, "Intro"); + setIfExists(m_Brief, "Brief"); + setIfExists(m_Win, "Win"); + setIfExists(m_Lose, "Lose"); + setIfExists(m_Action, "Action"); + setIfExists(m_PostScore, "PostScore"); + setIfExists(m_PreMapSelect, "PreMapSelect"); + + setIfExists(m_StartingDropships, "StartingDropships"); + setIfExists(m_CarryOverMoney, "CarryOverMoney"); + setIfExists(m_TimerInherit, "TimerInherit"); + setIfExists(m_FillSilos, "FillSilos"); ListMovies(m_Intro, TRUE); ListMovies(m_Brief, TRUE); @@ -130,70 +125,70 @@ void CSingleplayerSettings::UpdateDialog() UpdateStrings(); } -void CSingleplayerSettings::OnEditchangeIntro() +void CSingleplayerSettings::OnEditchangeIntro() { - CIniFile& ini=Map->GetIniFile(); - ini.sections["Basic"].values["Intro"]=GetText(&m_Intro); + CIniFile& ini = Map->GetIniFile(); + ini.SetString("Basic", "Intro", GetText(&m_Intro)); } void CSingleplayerSettings::OnEditchangeBrief() { CIniFile& ini=Map->GetIniFile(); - ini.sections["Basic"].values["Brief"]=GetText(&m_Brief); + ini.SetString("Basic", "Brief", GetText(&m_Brief)); } void CSingleplayerSettings::OnEditchangeWin() { CIniFile& ini=Map->GetIniFile(); - ini.sections["Basic"].values["Win"]=GetText(&m_Win); + ini.SetString("Basic", "Win", GetText(&m_Win)); } void CSingleplayerSettings::OnEditchangeLose() { CIniFile& ini=Map->GetIniFile(); - ini.sections["Basic"].values["Lose"]=GetText(&m_Lose); + ini.SetString("Basic", "Lose", GetText(&m_Lose)); } void CSingleplayerSettings::OnEditchangeAction() { CIniFile& ini=Map->GetIniFile(); - ini.sections["Basic"].values["Action"]=GetText(&m_Action); + ini.SetString("Basic", "Action", GetText(&m_Action)); } void CSingleplayerSettings::OnEditchangePostscore() { CIniFile& ini=Map->GetIniFile(); - ini.sections["Basic"].values["PostScore"]=GetText(&m_PostScore); + ini.SetString("Basic", "PostScore", GetText(&m_PostScore)); } void CSingleplayerSettings::OnEditchangePremapselect() { CIniFile& ini=Map->GetIniFile(); - ini.sections["Basic"].values["PreMapSelect"]=GetText(&m_PreMapSelect); + ini.SetString("Basic", "PreMapSelect", GetText(&m_PreMapSelect)); } void CSingleplayerSettings::OnEditchangeStartingdropships() { CIniFile& ini=Map->GetIniFile(); - ini.sections["Basic"].values["StartingDropships"]=GetText(&m_StartingDropships); + ini.SetString("Basic", "StartingDropships", GetText(&m_StartingDropships)); } void CSingleplayerSettings::OnChangeCarryovermoney() { CIniFile& ini=Map->GetIniFile(); - ini.sections["Basic"].values["CarryOverMoney"]=GetText(&m_CarryOverMoney); + ini.SetString("Basic", "CarryOverMoney", GetText(&m_CarryOverMoney)); } void CSingleplayerSettings::OnEditchangeTimerinherit() { CIniFile& ini=Map->GetIniFile(); - ini.sections["Basic"].values["TimerInherit"]=GetText(&m_TimerInherit); + ini.SetString("Basic", "TimerInherit", GetText(&m_TimerInherit)); } void CSingleplayerSettings::OnEditchangeFillsilos() { CIniFile& ini=Map->GetIniFile(); - ini.sections["Basic"].values["FillSilos"]=GetText(&m_FillSilos); + ini.SetString("Basic", "FillSilos", GetText(&m_FillSilos)); } void CSingleplayerSettings::UpdateStrings() diff --git a/MissionEditor/SpecialFlags.cpp b/MissionEditor/SpecialFlags.cpp index 20027c1..1399449 100644 --- a/MissionEditor/SpecialFlags.cpp +++ b/MissionEditor/SpecialFlags.cpp @@ -105,21 +105,20 @@ void CSpecialFlags::UpdateDialog() { CIniFile& ini=Map->GetIniFile(); - CIniFileSection *sec; - sec=&ini.sections["SpecialFlags"]; - m_DestroyableBridges.SetWindowText(sec->values["DestroyableBridges"]); - m_FixedAlliance.SetWindowText(sec->values["FixedAlliance"]); - m_FogOfWar.SetWindowText(sec->values["FogOfWar"]); - m_HarvesterImmune.SetWindowText(sec->values["HarvesterImmune"]); - m_Inert.SetWindowText(sec->values["Inert"]); - m_InitialVeteran.SetWindowText(sec->values["InitialVeteran"]); - m_IonStorms.SetWindowText(sec->values["IonStorms"]); - m_MCVDeploy.SetWindowText(sec->values["MCVDeploy"]); - m_Meteorites.SetWindowText(sec->values["Meteorites"]); - m_TiberiumExplosive.SetWindowText(sec->values["TiberiumExplosive"]); - m_TiberiumGrows.SetWindowText(sec->values["TiberiumGrows"]); - m_TiberiumSpreads.SetWindowText(sec->values["TiberiumSpreads"]); - m_Visceroids.SetWindowText(sec->values["Visceroids"]); + auto const& sec = ini["SpecialFlags"]; + m_DestroyableBridges.SetWindowText(sec.GetString("DestroyableBridges")); + m_FixedAlliance.SetWindowText(sec.GetString("FixedAlliance")); + m_FogOfWar.SetWindowText(sec.GetString("FogOfWar")); + m_HarvesterImmune.SetWindowText(sec.GetString("HarvesterImmune")); + m_Inert.SetWindowText(sec.GetString("Inert")); + m_InitialVeteran.SetWindowText(sec.GetString("InitialVeteran")); + m_IonStorms.SetWindowText(sec.GetString("IonStorms")); + m_MCVDeploy.SetWindowText(sec.GetString("MCVDeploy")); + m_Meteorites.SetWindowText(sec.GetString("Meteorites")); + m_TiberiumExplosive.SetWindowText(sec.GetString("TiberiumExplosive")); + m_TiberiumGrows.SetWindowText(sec.GetString("TiberiumGrows")); + m_TiberiumSpreads.SetWindowText(sec.GetString("TiberiumSpreads")); + m_Visceroids.SetWindowText(sec.GetString("Visceroids")); #ifdef RA2_MODE SetDlgItemText(IDC_LTIBERIUMGROWS,"Ore grows:"); @@ -144,168 +143,103 @@ void CSpecialFlags::UpdateDialog() void CSpecialFlags::OnEditchangeTiberiumgrows() { CIniFile& ini=Map->GetIniFile(); - - CIniFileSection *sec; - sec=&ini.sections["SpecialFlags"]; CString str; - - str=GetText(&m_TiberiumGrows); - sec->values["TiberiumGrows"]=(LPCTSTR)str; + ini.SetString("SpecialFlags", "TiberiumGrows", str); } void CSpecialFlags::OnEditchangeTiberiumspreads() { CIniFile& ini=Map->GetIniFile(); - - CIniFileSection *sec; - sec=&ini.sections["SpecialFlags"]; CString str; - - str=GetText(&m_TiberiumSpreads); - sec->values["TiberiumSpreads"]=(LPCTSTR)str; + ini.SetString("SpecialFlags", "TiberiumSpreads", str); } void CSpecialFlags::OnEditchangeTiberiumexplosive() { CIniFile& ini=Map->GetIniFile(); - - CIniFileSection *sec; - sec=&ini.sections["SpecialFlags"]; CString str; - - str=GetText(&m_TiberiumExplosive); - sec->values["TiberiumExplosive"]=(LPCTSTR)str; + ini.SetString("SpecialFlags", "TiberiumExplosive", str); } void CSpecialFlags::OnEditchangeDestroyablebridges() { CIniFile& ini=Map->GetIniFile(); - - CIniFileSection *sec; - sec=&ini.sections["SpecialFlags"]; CString str; - - str=GetText(&m_DestroyableBridges); - sec->values["DestroyableBridges"]=(LPCTSTR)str; + ini.SetString("SpecialFlags", "DestroyableBridges", str); } void CSpecialFlags::OnEditchangeMcvdeploy() { CIniFile& ini=Map->GetIniFile(); - - CIniFileSection *sec; - sec=&ini.sections["SpecialFlags"]; CString str; - - str=GetText(&m_MCVDeploy); - sec->values["MCVDeploy"]=(LPCTSTR)str; + ini.SetString("SpecialFlags", "MCVDeploy", str); } void CSpecialFlags::OnEditchangeInitialveteran() { CIniFile& ini=Map->GetIniFile(); - - CIniFileSection *sec; - sec=&ini.sections["SpecialFlags"]; CString str; - - str=GetText(&m_InitialVeteran); - sec->values["InitialVeteran"]=(LPCTSTR)str; + ini.SetString("SpecialFlags", "InitialVeteran", str); } void CSpecialFlags::OnEditchangeFixedalliance() { CIniFile& ini=Map->GetIniFile(); - - CIniFileSection *sec; - sec=&ini.sections["SpecialFlags"]; CString str; - - str=GetText(&m_FixedAlliance); - sec->values["FixedAlliance"]=(LPCTSTR)str; + ini.SetString("SpecialFlags", "FixedAlliance", str); } void CSpecialFlags::OnEditchangeHarvesterimmune() { CIniFile& ini=Map->GetIniFile(); - - CIniFileSection *sec; - sec=&ini.sections["SpecialFlags"]; CString str; - - str=GetText(&m_HarvesterImmune); - sec->values["HarvesterImmune"]=(LPCTSTR)str; + ini.SetString("SpecialFlags", "HarvesterImmune", str); } void CSpecialFlags::OnEditchangeFogofwar() { CIniFile& ini=Map->GetIniFile(); - - CIniFileSection *sec; - sec=&ini.sections["SpecialFlags"]; CString str; - - str=GetText(&m_FogOfWar); - sec->values["FogOfWar"]=(LPCTSTR)str; + ini.SetString("SpecialFlags", "FogOfWar", str); } void CSpecialFlags::OnEditchangeInert() { CIniFile& ini=Map->GetIniFile(); - - CIniFileSection *sec; - sec=&ini.sections["SpecialFlags"]; CString str; - - str=GetText(&m_Inert); - sec->values["Inert"]=(LPCTSTR)str; + ini.SetString("SpecialFlags", "Inert", str); } void CSpecialFlags::OnEditchangeIonstorms() { CIniFile& ini=Map->GetIniFile(); - - CIniFileSection *sec; - sec=&ini.sections["SpecialFlags"]; CString str; - - str=GetText(&m_IonStorms); - sec->values["IonStorms"]=(LPCTSTR)str; + ini.SetString("SpecialFlags", "IonStorms", str); } void CSpecialFlags::OnEditchangeMeteorites() { CIniFile& ini=Map->GetIniFile(); - - CIniFileSection *sec; - sec=&ini.sections["SpecialFlags"]; CString str; - - str=GetText(&m_Meteorites); - sec->values["Meteorites"]=(LPCTSTR)str; + ini.SetString("SpecialFlags", "Meteorites", str); } void CSpecialFlags::OnEditchangeVisceroids() { CIniFile& ini=Map->GetIniFile(); - - CIniFileSection *sec; - sec=&ini.sections["SpecialFlags"]; CString str; - - str=GetText(&m_Visceroids); - sec->values["Visceroids"]=(LPCTSTR)str; + ini.SetString("SpecialFlags", "Visceroids", str); } diff --git a/MissionEditor/TSOptions.cpp b/MissionEditor/TSOptions.cpp index e939af7..6d15d0b 100644 --- a/MissionEditor/TSOptions.cpp +++ b/MissionEditor/TSOptions.cpp @@ -92,7 +92,7 @@ void CTSOptions::OnOK() this->GetDlgItem(IDC_EDIT1)->GetWindowText(m_TSEXE); int n=m_Language.GetItemData(m_Language.GetCurSel()); - m_LanguageName=*language.sections["Languages"].GetValue(n); + m_LanguageName = language["Languages"].Nth(n).second; CDialog::OnOK(); } @@ -110,19 +110,15 @@ BOOL CTSOptions::OnInitDialog() UpdateData(FALSE); - int i; - for(i=0;iGetIniFile(); int index=m_Tag.GetCurSel(); - if(index<0) return; + if (index < 0) { + return; + } CString type; m_Tag.GetLBText(index, type); - if(type.Find(" ")>=0) type.SetAt(type.Find(" "),0); + if (type.Find(" ") >= 0) { + type.SetAt(type.Find(" "), 0); + } - CString data=ini.sections["Tags"].values[(LPCTSTR)type]; + CString data = ini.GetString("Tags", type); m_Name=GetParam(data,1); CString trigger=GetParam(data,2); CString typ=trigger; trigger+=" ("; - if(ini.sections["Triggers"].values.find(typ)!=ini.sections["Triggers"].values.end()) - trigger+=GetParam(ini.sections["Triggers"].values[typ],2); + auto const& def = ini.GetString("Triggers", typ); + if(!def.IsEmpty()) { + trigger += GetParam(def, 2); + } trigger+=")"; m_Trigger.SetWindowText(trigger); @@ -169,13 +170,13 @@ void CTags::OnChangeName() m_Tag.GetLBText(index, type); if(type.Find(" ")>=0) type.SetAt(type.Find(" "),0); - CString data=ini.sections["Tags"].values[(LPCTSTR)type]; + auto const& data = ini.GetString("Tags", type); CString tag, repeat; - tag=GetParam(data,2); - repeat=GetParam(data,0); - data=repeat+","+(LPCTSTR)m_Name+","+tag; - ini.sections["Tags"].values[(LPCTSTR)type]=data; + tag = GetParam(data, 2); + repeat = GetParam(data, 0); + auto const& constructed = repeat + "," + m_Name + "," + tag; + ini.SetString("Tags", type, constructed); UpdateDialog(); name.SetSel(sel2); @@ -186,22 +187,26 @@ void CTags::OnEditchangeRepeat() CIniFile& ini=Map->GetIniFile(); int index=m_Tag.GetCurSel(); - if(index<0) return; + if (index < 0) { + return; + } CString str; m_Repeat.GetWindowText(str); CString type; m_Tag.GetLBText(index, type); - if(type.Find(" ")>=0) type.SetAt(type.Find(" "),0); + if (type.Find(" ") >= 0) { + type.SetAt(type.Find(" "), 0); + } - CString data=ini.sections["Tags"].values[(LPCTSTR)type]; + auto const data=ini.GetString("Tags", type); CString trigger, name; - trigger=GetParam(data,2); - name=GetParam(data,1); - data=(CString)(LPCTSTR)str+","+name+","+trigger; - ini.sections["Tags"].values[(LPCTSTR)type]=data; + trigger = GetParam(data, 2); + name = GetParam(data, 1); + auto const constructed = str + "," + name + "," + trigger; + ini.SetString("Tags", type, constructed); UpdateDialog(); @@ -228,13 +233,13 @@ void CTags::OnSelchangeRepeat() TruncSpace(str); - CString data=ini.sections["Tags"].values[(LPCTSTR)type]; - + auto const data = ini.GetString("Tags", type); + CString trigger, name; - trigger=GetParam(data,2); - name=GetParam(data,1); - data=(CString)(LPCTSTR)str+","+name+","+trigger; - ini.sections["Tags"].values[(LPCTSTR)type]=data; + trigger = GetParam(data, 2); + name = GetParam(data, 1); + auto const constructed = str + "," + name + "," + trigger; + ini.SetString("Tags", type, constructed); UpdateDialog(); @@ -255,13 +260,13 @@ void CTags::OnEditchangeTrigger() m_Tag.GetLBText(index, type); if(type.Find(" ")>=0) type.SetAt(type.Find(" "),0); - CString data=ini.sections["Tags"].values[(LPCTSTR)type]; + auto const data = ini.GetString("Tags", type); CString repeat, name; - repeat=GetParam(data,0); - name=GetParam(data,1); - data=repeat+","+name+","+(LPCTSTR)str; - ini.sections["Tags"].values[(LPCTSTR)type]=data; + repeat = GetParam(data, 0); + name = GetParam(data, 1); + auto const constructed = repeat + "," + name + "," + (LPCTSTR)str; + ini.SetString("Tags", type, constructed); //UpdateDialog(); @@ -273,7 +278,9 @@ void CTags::OnSelchangeTrigger() CIniFile& ini=Map->GetIniFile(); int index=m_Tag.GetCurSel(); - if(index<0) return; + if (index < 0) { + return; + } int v=m_Trigger.GetCurSel(); CString str; @@ -281,20 +288,23 @@ void CTags::OnSelchangeTrigger() m_Trigger.GetLBText(v,str); - if(str.Find(" ")>=0) str.SetAt(str.Find(" "),0); + if (str.Find(" ") >= 0) { + str.SetAt(str.Find(" "), 0); + } CString type; m_Tag.GetLBText(index, type); - if(type.Find(" ")>=0) type.SetAt(type.Find(" "),0); + if (type.Find(" ") >= 0) { + type.SetAt(type.Find(" "), 0); + } - CString data=ini.sections["Tags"].values[(LPCTSTR)type]; + auto const data = ini.GetString("Tags", type); CString repeat, name; repeat=GetParam(data,0); name=GetParam(data,1); - data=repeat+","+name+","+(LPCTSTR)str; - ini.sections["Tags"].values[(LPCTSTR)type]=data; - + auto const constructed =repeat+","+name+","+(LPCTSTR)str; + ini.SetString("Tags", type, constructed); //UpdateDialog(); } @@ -304,16 +314,22 @@ void CTags::OnDelete() CIniFile& ini=Map->GetIniFile(); int index=m_Tag.GetCurSel(); - if(index<0) return; + if (index < 0) { + return; + } CString type; m_Tag.GetLBText(index, type); - if(type.Find(" ")>=0) type.SetAt(type.Find(" "),0); + if (type.Find(" ") >= 0) { + type.SetAt(type.Find(" "), 0); + } int res=MessageBox("Are you sure to delete the selected tag? This may cause the attached trigger to don´t work anymore, if no other tag has the trigger attached.","Delete tag", MB_YESNO); - if(res==IDNO) return; + if (res == IDNO) { + return; + } - ini.sections["Tags"].values.erase((LPCTSTR)type); + ini.RemoveValueByKey("Tags", type); UpdateDialog(); } @@ -323,16 +339,15 @@ void CTags::OnAdd() CString ID=GetFreeID(); - if(ini.sections["Triggers"].values.size()<1) - { + if (ini["Triggers"].Size() < 1) { MessageBox("Before creating tags, you need at least one trigger.","Error"); return; }; CString data; - data="0,New Tag,"; - data+=*ini.sections["Triggers"].GetValueName(0); - ini.sections["Tags"].values[ID]=data; + data = "0,New Tag,"; + data += ini["Triggers"].Nth(0).first; + ini.SetString("Tags", ID, data); UpdateDialog(); diff --git a/MissionEditor/TaskForce.cpp b/MissionEditor/TaskForce.cpp index 40f09ee..e6096b1 100644 --- a/MissionEditor/TaskForce.cpp +++ b/MissionEditor/TaskForce.cpp @@ -106,134 +106,46 @@ void CTaskForce::UpdateDialog() UpdateData(FALSE); int i; - CIniFileSection& sec=ini.sections["TaskForces"]; - for(i=0;iGetUnitName((char*)(LPCTSTR)type); + auto addIntoUnitTypeByIni = [this](const CIniFile& ini, const CString& section) { + for (auto const& [seq, type] : ini[section]) { + CString s; + s = type; + s += " ("; + /*if(ini.sections.find((char*)(LPCTSTR)type)!=ini.sections.end() && ini.sections[(char*)(LPCTSTR)type].values.find("Name")!=ini.sections[(char*)(LPCTSTR)type].values.end()) + s+=ini.sections[(char*)(LPCTSTR)type].values["Name"]; + else + s+=rules.sections[(char*)(LPCTSTR)type].values["Name"]; + */ + s += Map->GetUnitName((char*)(LPCTSTR)type); - s+=")"; - m_UnitType.AddString(s); - } - for(i=0;iGetUnitName((char*)(LPCTSTR)type); + s += ")"; + m_UnitType.AddString(s); + } + }; - s+=")"; - m_UnitType.AddString(s); - } + auto addIntoUnitType = [&addIntoUnitTypeByIni, &ini](const CString& section) { + addIntoUnitTypeByIni(rules, section); + addIntoUnitTypeByIni(ini, section); + }; + addIntoUnitType("InfantryTypes"); + addIntoUnitType("VehicleTypes"); + addIntoUnitType("AircraftTypes"); - ss="VehicleTypes"; - for(i=0;iGetUnitName((char*)(LPCTSTR)type); - - s+=")"; - m_UnitType.AddString(s); - } - for(i=0;iGetUnitName((char*)(LPCTSTR)type); - - s+=")"; - m_UnitType.AddString(s); - } - - ss="AircraftTypes"; - for(i=0;iGetUnitName((char*)(LPCTSTR)type); - - s+=")"; - m_UnitType.AddString(s); - } - for(i=0;iGetUnitName((char*)(LPCTSTR)type); - - s+=")"; - m_UnitType.AddString(s); - } - - - if(sel<0) - { - if(m_TaskForces.SetCurSel(0)!=CB_ERR) + if (sel < 0) { + if (m_TaskForces.SetCurSel(0) != CB_ERR) OnSelchangeTaskforces(); - } - else - { - if(m_TaskForces.SetCurSel(sel)!=CB_ERR) + } else { + if (m_TaskForces.SetCurSel(sel) != CB_ERR) OnSelchangeTaskforces(); } @@ -264,36 +176,33 @@ void CTaskForce::OnSelchangeTaskforces() tf=GetText(&m_TaskForces); TruncSpace(tf); - CIniFileSection & sec=ini.sections[(char*)(LPCTSTR)tf]; - m_Name=sec.values["Name"]; - m_Group=sec.values["Group"]; + auto const & sec=ini[tf]; + m_Name = sec.GetString("Name"); + m_Group = sec.GetString("Group"); int i; - while(m_Units.DeleteString(0)!=LB_ERR); - for(i=0;iGetUnitName(type); + s += Map->GetUnitName(type); //s+=")"; - - m_Units.SetItemData(m_Units.AddString(s), i); - + m_Units.SetItemData(m_Units.AddString(s), i); } UpdateData(FALSE); - if(m_Units.SetCurSel(0)!=LB_ERR) OnSelchangeUnits(); - - + if (m_Units.SetCurSel(0) != LB_ERR) { + OnSelchangeUnits(); + } } void CTaskForce::OnSelchangeUnits() @@ -305,11 +214,8 @@ void CTaskForce::OnSelchangeUnits() CString tf; tf=GetText(&m_TaskForces); TruncSpace(tf); - CIniFileSection & sec=ini.sections[(char*)(LPCTSTR)tf]; - - char k[50]; - itoa(u, k, 10); - CString data=sec.values[k]; + auto const& sec = ini[tf]; + auto const& data=sec.Nth(u).second; CString c=GetParam(data, 0); CString s; @@ -331,31 +237,34 @@ void CTaskForce::OnDeleteunit() CIniFile& ini=Map->GetIniFile(); int sel=m_Units.GetCurSel(); - if(sel<0) return; + if (sel < 0) { + return; + } int u=m_Units.GetItemData(sel); CString tf; - tf=GetText(&m_TaskForces); + tf = GetText(&m_TaskForces); TruncSpace(tf); - CIniFileSection & sec=ini.sections[(char*)(LPCTSTR)tf]; - + auto sec = ini.TryGetSection(tf); + ASSERT(sec != nullptr); char k[50]; itoa(u, k, 10); - if(sec.values.size()<4) { - sec.values.erase(k); + + if (sec->Size() < 4) { + sec->RemoveByKey(k); m_Units.DeleteString(sel); m_UnitType.SetWindowText(""); - m_NumberOfUnits=atoi("0"); + m_NumberOfUnits = atoi("0"); UpdateDialog(); - return; } - int lastpos=sec.values.size()-3; + int lastpos = sec->Size() - 3; char l[50]; itoa(lastpos, l, 10); - sec.values[k]=sec.values[l]; - sec.values.erase(l); + sec->SetString(k, sec->GetString(l)); + sec->RemoveByKey(l); + sec->RemoveAt(lastpos); m_Units.DeleteString(sel); @@ -370,20 +279,22 @@ void CTaskForce::OnChangeNumberunits() UpdateData(); int sel=m_Units.GetCurSel(); - if(sel<0) return; + if (sel < 0) { + return; + } int u=m_Units.GetItemData(sel); CString tf; tf=GetText(&m_TaskForces); TruncSpace(tf); - CIniFileSection & sec=ini.sections[(char*)(LPCTSTR)tf]; + auto sec = ini.TryGetSection(tf); - char k[50], n[50];; + char k[50], n[50]; itoa(u, k, 10); itoa(m_NumberOfUnits, n, 10); - CString data=sec.values[k]; + auto const& data=sec->GetString(k); CString c=GetParam(data, 1); - sec.values[k]=n+(CString)","+c; + sec->SetString(k, n + (CString)"," + c); UpdateDialog(); } @@ -396,14 +307,15 @@ void CTaskForce::OnChangeName() CEdit& n=*(CEdit*)GetDlgItem(IDC_NAME); DWORD pos=n.GetSel(); - if(m_TaskForces.GetCurSel()<0) return; + if (m_TaskForces.GetCurSel() < 0) { + return; + } CString tf; tf=GetText(&m_TaskForces); TruncSpace(tf); - CIniFileSection & sec=ini.sections[(char*)(LPCTSTR)tf]; - - sec.values["Name"]=m_Name; + + ini.SetString(tf, "Name", m_Name); UpdateDialog(); n.SetSel(pos); @@ -414,22 +326,24 @@ void CTaskForce::OnEditchangeUnittype() CIniFile& ini=Map->GetIniFile(); int sel=m_Units.GetCurSel(); - if(sel<0) return; + if (sel < 0) { + return; + } int u=m_Units.GetItemData(sel); CString tf; tf=GetText(&m_TaskForces); TruncSpace(tf); - CIniFileSection & sec=ini.sections[(char*)(LPCTSTR)tf]; - + auto sec = ini.TryGetSection(tf); + ASSERT(sec != nullptr); char k[50]; itoa(u, k, 10); - CString count=GetParam(sec.values[k],0); + CString count = GetParam(sec->GetString(k), 0); CString type=GetText(&m_UnitType); TruncSpace(type); - sec.values[k]=count+","+(char*)(LPCTSTR)type; + sec->SetString(k, count + "," + (char*)(LPCTSTR)type); CString ut; m_UnitType.GetWindowText(ut); @@ -444,23 +358,26 @@ void CTaskForce::OnSelchangeUnittype() CIniFile& ini=Map->GetIniFile(); int sel=m_Units.GetCurSel(); - if(sel<0) return; + if (sel < 0) { + return; + } int u=m_Units.GetItemData(sel); CString tf; tf=GetText(&m_TaskForces); TruncSpace(tf); - CIniFileSection & sec=ini.sections[(char*)(LPCTSTR)tf]; - + auto sec = ini.TryGetSection(tf); + ASSERT(sec != nullptr); + char k[50]; itoa(u, k, 10); - CString count=GetParam(sec.values[k],0); + CString count=GetParam(sec->GetString(k), 0); CString type=GetText(&m_UnitType); TruncSpace(type); - sec.values[k]=count+","+(char*)(LPCTSTR)type; + sec->SetString(k, count + "," + type); UpdateDialog(); //m_UnitType.SetWindowText("H"); @@ -471,18 +388,23 @@ void CTaskForce::OnAddunit() CIniFile& ini=Map->GetIniFile(); CString tf; - if(m_TaskForces.GetCurSel()<0) return; + if (m_TaskForces.GetCurSel() < 0) { + return; + } tf=GetText(&m_TaskForces); TruncSpace(tf); - CIniFileSection & sec=ini.sections[(char*)(LPCTSTR)tf]; - + auto sec = ini.TryGetSection(tf); + ASSERT(sec != nullptr); + char k[50]; int c=m_Units.GetCount(); - if(c==LB_ERR) c=0; + if (c == LB_ERR) { + c = 0; + } itoa(c, k, 10); - sec.values[k]="1"+(CString)","+*rules.sections["InfantryTypes"].GetValue(0); + sec->SetString(k, "1" + (CString)"," + rules["InfantryTypes"].Nth(0).second); UpdateDialog(); } @@ -492,21 +414,21 @@ void CTaskForce::OnDeletetaskforce() CIniFile& ini=Map->GetIniFile(); CString tf; - if(m_TaskForces.GetCurSel()<0) return; + if (m_TaskForces.GetCurSel() < 0) { + return; + } tf=GetText(&m_TaskForces); TruncSpace(tf); - CIniFileSection & sec=ini.sections[(char*)(LPCTSTR)tf]; - + int res; res=MessageBox("Are you sure to delete the selected task force? If you delete it, make sure to eliminate ANY references to this task force in team-types.","Delete task force",MB_YESNO); - if(res==IDNO) return; + if (res == IDNO) { + return; + } - int v=ini.sections["TaskForces"].FindValue((char*)(LPCTSTR)tf); - if(v==-1) return; // SHOULD NEVER BE!!!! AND CANNOT BE!!! BUT MAYBE A BUG... - - ini.sections["TaskForces"].values.erase(*ini.sections["TaskForces"].GetValueName(v)); - ini.sections.erase((char*)(LPCTSTR)tf); + ini.RemoveValueByKey("TaskForces", tf); + ini.DeleteSection(tf); while(m_Units.DeleteString(0)!=LB_ERR); //UpdateDialog(); ((CFinalSunDlg*)theApp.m_pMainWnd)->UpdateDialogs(TRUE); @@ -519,10 +441,10 @@ void CTaskForce::OnAddtaskforce() CString ID=GetFreeID(); CString tf=GetFree("TaskForces"); - ini.sections["TaskForces"].values[tf]=ID; + ini.SetString("TaskForces", tf, ID); - ini.sections[ID].values["Name"]="New task force"; - ini.sections[ID].values["Group"]="-1"; + ini.SetString(ID, "Name", "New task force"); + ini.SetString(ID, "Group", "-1"); //UpdateDialog(); @@ -554,13 +476,14 @@ void CTaskForce::OnChangeGroup() UpdateData(); CString tf; - if(m_TaskForces.GetCurSel()<0) return; + if (m_TaskForces.GetCurSel() < 0) { + return; + } tf=GetText(&m_TaskForces); TruncSpace(tf); - CIniFileSection & sec=ini.sections[(char*)(LPCTSTR)tf]; - - sec.values["Group"]=m_Group; + + ini.SetString(tf, "Group", m_Group); UpdateDialog(); diff --git a/MissionEditor/TeamTypes.cpp b/MissionEditor/TeamTypes.cpp index 2ff70ea..6b12537 100644 --- a/MissionEditor/TeamTypes.cpp +++ b/MissionEditor/TeamTypes.cpp @@ -361,56 +361,23 @@ void CTeamTypes::UpdateDialog() UpdateData(FALSE); int i; - for(i=0;iDeleteString(0)!=CB_ERR); + while (wayp->DeleteString(0) != CB_ERR); // houses: rules.ini + map definitions! - if(ini.sections.find("Waypoints")!=ini.sections.end()) - { - for(i=0;iAddString(*ini.sections["Waypoints"].GetValueName(i)); - } + for (auto const& [num, _] : ini["Waypoints"]) { + wayp->AddString(num); } wayp=(CComboBox*)GetDlgItem(IDC_TRANSPORTWAYPOINT); @@ -461,12 +424,8 @@ void CTeamTypes::UpdateDialog() // houses: rules.ini + map definitions! wayp->SetItemData(wayp->InsertString(0,TranslateStringACP("None")),0); - if(ini.sections.find("Waypoints")!=ini.sections.end()) - { - for(i=0;iSetItemData(wayp->AddString(*ini.sections["Waypoints"].GetValueName(i)),1); - } + for (auto const& [num, _] : ini["Waypoints"]) { + wayp->SetItemData(wayp->AddString(num), 1); } #ifdef TS_MODE @@ -474,7 +433,9 @@ void CTeamTypes::UpdateDialog() #endif m_TeamTypes.SetCurSel(0); - if(sel>=0) m_TeamTypes.SetCurSel(sel); + if (sel >= 0) { + m_TeamTypes.SetCurSel(sel); + } OnSelchangeTeamtypes(); @@ -484,66 +445,69 @@ void CTeamTypes::OnSelchangeTeamtypes() { CIniFile& ini=Map->GetIniFile(); - if(m_TeamTypes.GetCurSel()<0) return; + if (m_TeamTypes.GetCurSel() < 0) { + return; + } CString str; str=GetText(&m_TeamTypes); TruncSpace(str); - CIniFileSection& sec=ini.sections[(char*)(LPCTSTR)str]; + auto const& sec = ini[str]; - m_Aggressive=stob(sec.values["Aggressive"]); - m_Annoyance=stob(sec.values["Annoyance"]); - m_AreTeamMembersRecruitable=stob(sec.values["AreTeamMembersRecruitable"]); - m_Autocreate=stob(sec.values["Autocreate"]); - m_AvoidThreats=stob(sec.values["AvoidThreats"]); - m_Droppod=stob(sec.values["Droppod"]); - m_Full=stob(sec.values["Full"]); - m_Group=sec.values["Group"]; - m_GuardSlower=stob(sec.values["GuardSlower"]); - m_House=TranslateHouse(sec.values["House"], TRUE); - m_IonImmune=stob(sec.values["IonImmune"]); - m_IsBaseDefense=stob(sec.values["IsBaseDefense"]); - m_Loadable=stob(sec.values["Loadable"]); - m_LooseRecruit=stob(sec.values["LooseRecruit"]); - m_Max=sec.values["Max"]; - m_Name=sec.values["Name"]; - m_OnlyTargetHouseEnemy=stob(sec.values["OnlyTargetHouseEnemy"]); - m_OnTransOnly=stob(sec.values["OnTransOnly"]); - m_Prebuild=stob(sec.values["Prebuild"]); - m_Priority=sec.values["Priority"]; - m_Recruiter=stob(sec.values["Recruiter"]); - m_Reinforce=stob(sec.values["Reinforce"]); - m_Script=(sec.values["Script"]); - if(ini.sections.find(sec.values["Script"])!=ini.sections.end()) - m_Script+=(" ("+ini.sections[sec.values["Script"]].values["Name"]+")"); - m_Suicide=stob(sec.values["Suicide"]); - if(sec.values.find("Tag")!=sec.values.end()) - { - m_Tag=sec.values["Tag"]; - if(ini.sections["Tags"].values.find((LPCTSTR)m_Tag)!=ini.sections["Tags"].values.end()) - { - CString tag=m_Tag; - m_Tag+=" "; - m_Tag+=GetParam(ini.sections["Tags"].values[(LPCTSTR)tag], 1); + m_Aggressive= sec.GetBool("Aggressive"); + m_Annoyance = sec.GetBool("Annoyance"); + m_AreTeamMembersRecruitable = sec.GetBool("AreTeamMembersRecruitable"); + m_Autocreate = sec.GetBool("Autocreate"); + m_AvoidThreats = sec.GetBool("AvoidThreats"); + m_Droppod = sec.GetBool("Droppod"); + m_Full = sec.GetBool("Full"); + m_Group = sec.GetString("Group"); + m_GuardSlower = sec.GetBool("GuardSlower"); + m_House = TranslateHouse(sec.GetString("House"), TRUE); + m_IonImmune = sec.GetBool("IonImmune"); + m_IsBaseDefense = sec.GetBool("IsBaseDefense"); + m_Loadable = sec.GetBool("Loadable"); + m_LooseRecruit = sec.GetBool("LooseRecruit"); + m_Max = sec.GetString("Max"); + m_Name = sec.GetString("Name"); + m_OnlyTargetHouseEnemy = sec.GetBool("OnlyTargetHouseEnemy"); + m_OnTransOnly = sec.GetBool("OnTransOnly"); + m_Prebuild = sec.GetBool("Prebuild"); + m_Priority = sec.GetString("Priority"); + m_Recruiter = sec.GetBool("Recruiter"); + m_Reinforce = sec.GetBool("Reinforce"); + m_Script = (sec.GetString("Script")); + m_Script += " (" + ini.GetString(sec.GetString("Script"), "Name") + ")"; + m_Suicide = sec.GetBool("Suicide"); + + auto const& tagId = sec.GetString("Tag"); + if (!tagId.IsEmpty()) { + m_Tag = tagId; + auto const& tagDef = ini.GetString("Tags", tagId); + if (!tagDef.IsEmpty()) { + CString tag = m_Tag; + m_Tag += " "; + m_Tag += GetParam(tagDef, 1); } + } else { + m_Tag = GetLanguageStringACP("None"); } - else - { - m_Tag=GetLanguageStringACP("None"); + m_TaskForce = sec["TaskForce"]; + auto const& taskForceName = ini.GetString(m_TaskForce, "Name"); + if (!taskForceName.IsEmpty()) { + m_TaskForce += " (" + taskForceName + ")"; } - m_TaskForce=(sec.values["TaskForce"]); - if(ini.sections.find(sec.values["TaskForce"])!=ini.sections.end()) - m_TaskForce+=(" ("+ini.sections[sec.values["TaskForce"]].values["Name"]+")"); - m_TechLevel=sec.values["TechLevel"]; - m_TransportReturnsOnUnload=stob(sec.values["TransportsReturnOnUnload"]); - m_VeteranLevel=sec.values["VeteranLevel"]; + m_TechLevel = sec.GetString("TechLevel"); + m_TransportReturnsOnUnload= sec.GetBool("TransportsReturnOnUnload"); + m_VeteranLevel = sec.GetString("VeteranLevel"); - if(yuri_mode) - m_MindControlDecision=sec.values["MindControlDecision"]; + if (yuri_mode) { + m_MindControlDecision = sec.GetString("MindControlDecision"); + } - int w=GetWaypoint(sec.values["Waypoint"]); + int w = GetWaypoint(sec["Waypoint"]); char c[50]; itoa(w,c,10); if(w!=-1) @@ -552,22 +516,21 @@ void CTeamTypes::OnSelchangeTeamtypes() m_Waypoint=""; #ifdef RA2_MODE - if(isTrue(sec.values["UseTransportOrigin"])) - { - int w=GetWaypoint(sec.values["TransportWaypoint"]); + if (sec.GetBool("UseTransportOrigin")) { + int w = GetWaypoint(sec["TransportWaypoint"]); char c[50]; - itoa(w,c,10); - if(w!=-1) - m_TransportWaypoint=c; + itoa(w, c, 10); + if (w != -1) + m_TransportWaypoint = c; else - m_TransportWaypoint=""; + m_TransportWaypoint = ""; + } else { + m_TransportWaypoint = TranslateStringACP("None"); } - else - m_TransportWaypoint=TranslateStringACP("None"); #endif - m_Whiner=stob(sec.values["Whiner"]); + m_Whiner= sec.GetBool("Whiner"); UpdateData(FALSE); } @@ -585,9 +548,8 @@ void CTeamTypes::OnChangeName() CString str; str=GetText(&m_TeamTypes); TruncSpace(str); - CIniFileSection& sec=ini.sections[(char*)(LPCTSTR)str]; - sec.values["Name"]=m_Name; + ini.SetString(str, "Name", m_Name); UpdateDialog(); @@ -598,25 +560,22 @@ void CTeamTypes::OnDeleteteamtype() { CIniFile& ini=Map->GetIniFile(); - if(m_TeamTypes.GetCurSel()!=-1) - { + if (m_TeamTypes.GetCurSel() != -1) { int res=MessageBox("Are you sure that you want to delete the selected team-type? If you delete it, don´t forget to delete any reference to the team-type.","Delete team-type",MB_YESNO); - if(res==IDNO) return; + if (res == IDNO) { + return; + } CString str; str=GetText(&m_TeamTypes); TruncSpace(str); - int i; CIniFile& ini=Map->GetIniFile(); - for(i=0;iRemoveValue(str); } - ini.sections.erase((char*)(LPCTSTR)str); + ini.DeleteSection(str); } ((CFinalSunDlg*)theApp.m_pMainWnd)->UpdateDialogs(TRUE); //UpdateDialog(); @@ -627,29 +586,31 @@ void CTeamTypes::OnEditchangeVeteranlevel() CIniFile& ini=Map->GetIniFile(); UpdateData(TRUE); - if(m_TeamTypes.GetCount()==0) return; + if (m_TeamTypes.GetCount() == 0) { + return; + } CString str; str=GetText(&m_TeamTypes); TruncSpace(str); - CIniFileSection& sec=ini.sections[(char*)(LPCTSTR)str]; - sec.values["VeteranLevel"]=m_VeteranLevel; + ini.SetString(str, "VeteranLevel", m_VeteranLevel); } -void CTeamTypes::OnEditchangeHouse() +void CTeamTypes::OnEditchangeHouse() { CIniFile& ini=Map->GetIniFile(); UpdateData(TRUE); - if(m_TeamTypes.GetCount()==0) return; + if (m_TeamTypes.GetCount() == 0) { + return; + } CString str; - str=GetText(&m_TeamTypes); + str = GetText(&m_TeamTypes); TruncSpace(str); - CIniFileSection& sec=ini.sections[(char*)(LPCTSTR)str]; - sec.values["House"]=TranslateHouse(m_House); + ini.SetString(str, "House", TranslateHouse(m_House)); } void CTeamTypes::OnChangePriority() @@ -657,14 +618,15 @@ void CTeamTypes::OnChangePriority() CIniFile& ini=Map->GetIniFile(); UpdateData(TRUE); - if(m_TeamTypes.GetCount()==0) return; + if (m_TeamTypes.GetCount() == 0) { + return; + } CString str; str=GetText(&m_TeamTypes); TruncSpace(str); - CIniFileSection& sec=ini.sections[(char*)(LPCTSTR)str]; - sec.values["Priority"]=m_Priority; + ini.SetString(str, "Priority", m_Priority); } void CTeamTypes::OnChangeMax() @@ -672,14 +634,15 @@ void CTeamTypes::OnChangeMax() CIniFile& ini=Map->GetIniFile(); UpdateData(TRUE); - if(m_TeamTypes.GetCount()==0) return; + if (m_TeamTypes.GetCount() == 0) { + return; + } CString str; str=GetText(&m_TeamTypes); TruncSpace(str); - CIniFileSection& sec=ini.sections[(char*)(LPCTSTR)str]; - sec.values["Max"]=m_Max; + ini.SetString(str, "Max", m_Max); } void CTeamTypes::OnEditchangeTechlevel() @@ -687,14 +650,15 @@ void CTeamTypes::OnEditchangeTechlevel() CIniFile& ini=Map->GetIniFile(); UpdateData(TRUE); - if(m_TeamTypes.GetCount()==0) return; + if (m_TeamTypes.GetCount() == 0) { + return; + } CString str; str=GetText(&m_TeamTypes); TruncSpace(str); - CIniFileSection& sec=ini.sections[(char*)(LPCTSTR)str]; - sec.values["TechLevel"]=m_TechLevel; + ini.SetString(str, "TechLevel", m_TechLevel); } void CTeamTypes::OnEditchangeGroup() @@ -702,16 +666,15 @@ void CTeamTypes::OnEditchangeGroup() CIniFile& ini=Map->GetIniFile(); UpdateData(TRUE); - if(m_TeamTypes.GetCount()==0) return; + if (m_TeamTypes.GetCount() == 0) { + return; + } CString str; str=GetText(&m_TeamTypes); TruncSpace(str); - CIniFileSection& sec=ini.sections[(char*)(LPCTSTR)str]; - //MessageBox(str); - - sec.values["Group"]=m_Group; + ini.SetString(str, "Group", m_Group); } void CTeamTypes::OnEditchangeWaypoint() @@ -719,16 +682,21 @@ void CTeamTypes::OnEditchangeWaypoint() CIniFile& ini=Map->GetIniFile(); UpdateData(TRUE); - if(m_TeamTypes.GetCount()==0) return; + if (m_TeamTypes.GetCount() == 0) { + return; + } CString str; str=GetText(&m_TeamTypes); TruncSpace(str); - CIniFileSection& sec=ini.sections[(char*)(LPCTSTR)str]; + auto sec = ini.TryGetSection(str); + ASSERT(sec != nullptr); - if(strlen(m_Waypoint)==0) sec.values["Waypoint"]=""; - else - sec.values["Waypoint"]=GetWaypoint(atoi(m_Waypoint)); + if (strlen(m_Waypoint) == 0) { + sec->SetString("Waypoint", ""); + } else { + sec->SetString("Waypoint", GetWaypoint(atoi(m_Waypoint))); + } } void CTeamTypes::OnEditchangeScript() @@ -736,17 +704,17 @@ void CTeamTypes::OnEditchangeScript() CIniFile& ini=Map->GetIniFile(); UpdateData(TRUE); - if(m_TeamTypes.GetCount()==0) return; + if (m_TeamTypes.GetCount() == 0) { + return; + } CString str; str=GetText(&m_TeamTypes); TruncSpace(str); - CIniFileSection& sec=ini.sections[(char*)(LPCTSTR)str]; CString tmp=m_Script; TruncSpace(tmp); - sec.values["Script"]=tmp; - + ini.SetString(str, "Script", tmp); } void CTeamTypes::OnEditchangeTaskforce() @@ -754,16 +722,17 @@ void CTeamTypes::OnEditchangeTaskforce() CIniFile& ini=Map->GetIniFile(); UpdateData(TRUE); - if(m_TeamTypes.GetCount()==0) return; + if (m_TeamTypes.GetCount() == 0) { + return; + } CString str; str=GetText(&m_TeamTypes); TruncSpace(str); - CIniFileSection& sec=ini.sections[(char*)(LPCTSTR)str]; CString tmp=m_TaskForce; TruncSpace(tmp); - sec.values["TaskForce"]=tmp; + ini.SetString(str, "TaskForce", tmp); } @@ -831,14 +800,15 @@ void CTeamTypes::OnLoadable() CIniFile& ini=Map->GetIniFile(); UpdateData(TRUE); - if(m_TeamTypes.GetCount()==0) return; + if (m_TeamTypes.GetCount() == 0) { + return; + } CString str; str=GetText(&m_TeamTypes); TruncSpace(str); - CIniFileSection& sec=ini.sections[(char*)(LPCTSTR)str]; - sec.values["Loadable"]=btos(m_Loadable); + ini.SetBool(str, "Loadable", m_Loadable); } void CTeamTypes::OnFull() @@ -846,14 +816,15 @@ void CTeamTypes::OnFull() CIniFile& ini=Map->GetIniFile(); UpdateData(TRUE); - if(m_TeamTypes.GetCount()==0) return; + if (m_TeamTypes.GetCount() == 0) { + return; + } CString str; str=GetText(&m_TeamTypes); TruncSpace(str); - CIniFileSection& sec=ini.sections[(char*)(LPCTSTR)str]; - sec.values["Full"]=btos(m_Full); + ini.SetBool(str, "Loadable", m_Full); } void CTeamTypes::OnAnnoyance() @@ -861,14 +832,15 @@ void CTeamTypes::OnAnnoyance() CIniFile& ini=Map->GetIniFile(); UpdateData(TRUE); - if(m_TeamTypes.GetCount()==0) return; + if (m_TeamTypes.GetCount() == 0) { + return; + } CString str; str=GetText(&m_TeamTypes); TruncSpace(str); - CIniFileSection& sec=ini.sections[(char*)(LPCTSTR)str]; - sec.values["Annoyance"]=btos(m_Annoyance); + ini.SetBool(str, "Annoyance", m_Annoyance); } void CTeamTypes::OnGuardslower() @@ -876,14 +848,15 @@ void CTeamTypes::OnGuardslower() CIniFile& ini=Map->GetIniFile(); UpdateData(TRUE); - if(m_TeamTypes.GetCount()==0) return; + if (m_TeamTypes.GetCount() == 0) { + return; + } CString str; str=GetText(&m_TeamTypes); TruncSpace(str); - CIniFileSection& sec=ini.sections[(char*)(LPCTSTR)str]; - sec.values["GuardSlower"]=btos(m_GuardSlower); + ini.SetBool(str, "Annoyance", m_GuardSlower); } void CTeamTypes::OnRecruiter() @@ -891,14 +864,15 @@ void CTeamTypes::OnRecruiter() CIniFile& ini=Map->GetIniFile(); UpdateData(TRUE); - if(m_TeamTypes.GetCount()==0) return; + if (m_TeamTypes.GetCount() == 0) { + return; + } CString str; str=GetText(&m_TeamTypes); TruncSpace(str); - CIniFileSection& sec=ini.sections[(char*)(LPCTSTR)str]; - sec.values["Recruiter"]=btos(m_Recruiter); + ini.SetBool(str, "Annoyance", m_Recruiter); } void CTeamTypes::OnDroppod() @@ -906,14 +880,15 @@ void CTeamTypes::OnDroppod() CIniFile& ini=Map->GetIniFile(); UpdateData(TRUE); - if(m_TeamTypes.GetCount()==0) return; + if (m_TeamTypes.GetCount() == 0) { + return; + } CString str; str=GetText(&m_TeamTypes); TruncSpace(str); - CIniFileSection& sec=ini.sections[(char*)(LPCTSTR)str]; - sec.values["Droppod"]=btos(m_Droppod); + ini.SetBool(str, "Annoyance", m_Droppod); } void CTeamTypes::OnWhiner() @@ -921,14 +896,15 @@ void CTeamTypes::OnWhiner() CIniFile& ini=Map->GetIniFile(); UpdateData(TRUE); - if(m_TeamTypes.GetCount()==0) return; + if (m_TeamTypes.GetCount() == 0) { + return; + } CString str; str=GetText(&m_TeamTypes); TruncSpace(str); - CIniFileSection& sec=ini.sections[(char*)(LPCTSTR)str]; - sec.values["Whiner"]=btos(m_Whiner); + ini.SetBool(str, "Whiner", m_Whiner); } void CTeamTypes::OnLooserecruit() @@ -936,14 +912,15 @@ void CTeamTypes::OnLooserecruit() CIniFile& ini=Map->GetIniFile(); UpdateData(TRUE); - if(m_TeamTypes.GetCount()==0) return; + if (m_TeamTypes.GetCount() == 0) { + return; + } CString str; str=GetText(&m_TeamTypes); TruncSpace(str); - CIniFileSection& sec=ini.sections[(char*)(LPCTSTR)str]; - sec.values["LooseRecruit"]=btos(m_LooseRecruit); + ini.SetBool(str, "LooseRecruit", m_LooseRecruit); } void CTeamTypes::OnAggressive() @@ -951,14 +928,15 @@ void CTeamTypes::OnAggressive() CIniFile& ini=Map->GetIniFile(); UpdateData(TRUE); - if(m_TeamTypes.GetCount()==0) return; + if (m_TeamTypes.GetCount() == 0) { + return; + } CString str; str=GetText(&m_TeamTypes); TruncSpace(str); - CIniFileSection& sec=ini.sections[(char*)(LPCTSTR)str]; - sec.values["Aggressive"]=btos(m_Aggressive); + ini.SetBool(str, "LooseRecruit", m_Aggressive); } void CTeamTypes::OnSuicide() @@ -966,14 +944,15 @@ void CTeamTypes::OnSuicide() CIniFile& ini=Map->GetIniFile(); UpdateData(TRUE); - if(m_TeamTypes.GetCount()==0) return; + if (m_TeamTypes.GetCount() == 0) { + return; + } CString str; str=GetText(&m_TeamTypes); TruncSpace(str); - CIniFileSection& sec=ini.sections[(char*)(LPCTSTR)str]; - sec.values["Suicide"]=btos(m_Suicide); + ini.SetBool(str, "Suicide", m_Suicide); } void CTeamTypes::OnAutocreate() @@ -981,14 +960,15 @@ void CTeamTypes::OnAutocreate() CIniFile& ini=Map->GetIniFile(); UpdateData(TRUE); - if(m_TeamTypes.GetCount()==0) return; + if (m_TeamTypes.GetCount() == 0) { + return; + } CString str; str=GetText(&m_TeamTypes); TruncSpace(str); - CIniFileSection& sec=ini.sections[(char*)(LPCTSTR)str]; - sec.values["Autocreate"]=btos(m_Autocreate); + ini.SetBool(str, "Autocreate", m_Autocreate); } void CTeamTypes::OnPrebuild() @@ -996,14 +976,15 @@ void CTeamTypes::OnPrebuild() CIniFile& ini=Map->GetIniFile(); UpdateData(TRUE); - if(m_TeamTypes.GetCount()==0) return; + if (m_TeamTypes.GetCount() == 0) { + return; + } CString str; str=GetText(&m_TeamTypes); TruncSpace(str); - CIniFileSection& sec=ini.sections[(char*)(LPCTSTR)str]; - sec.values["Prebuild"]=btos(m_Prebuild); + ini.SetBool(str, "Prebuild", m_Prebuild); } void CTeamTypes::OnOntransonly() @@ -1011,14 +992,15 @@ void CTeamTypes::OnOntransonly() CIniFile& ini=Map->GetIniFile(); UpdateData(TRUE); - if(m_TeamTypes.GetCount()==0) return; + if (m_TeamTypes.GetCount() == 0) { + return; + } CString str; str=GetText(&m_TeamTypes); TruncSpace(str); - CIniFileSection& sec=ini.sections[(char*)(LPCTSTR)str]; - sec.values["OnTransOnly"]=btos(m_OnTransOnly); + ini.SetBool(str, "OnTransOnly", m_OnTransOnly); } void CTeamTypes::OnReinforce() @@ -1026,14 +1008,15 @@ void CTeamTypes::OnReinforce() CIniFile& ini=Map->GetIniFile(); UpdateData(TRUE); - if(m_TeamTypes.GetCount()==0) return; + if (m_TeamTypes.GetCount() == 0) { + return; + } CString str; str=GetText(&m_TeamTypes); TruncSpace(str); - CIniFileSection& sec=ini.sections[(char*)(LPCTSTR)str]; - sec.values["Reinforce"]=btos(m_Reinforce); + ini.SetBool(str, "Reinforce", m_Reinforce); } void CTeamTypes::OnAvoidthreats() @@ -1041,14 +1024,15 @@ void CTeamTypes::OnAvoidthreats() CIniFile& ini=Map->GetIniFile(); UpdateData(TRUE); - if(m_TeamTypes.GetCount()==0) return; + if (m_TeamTypes.GetCount() == 0) { + return; + } CString str; str=GetText(&m_TeamTypes); TruncSpace(str); - CIniFileSection& sec=ini.sections[(char*)(LPCTSTR)str]; - sec.values["AvoidThreats"]=btos(m_AvoidThreats); + ini.SetBool(str, "Reinforce", m_AvoidThreats); } void CTeamTypes::OnIonimmune() @@ -1056,14 +1040,15 @@ void CTeamTypes::OnIonimmune() CIniFile& ini=Map->GetIniFile(); UpdateData(TRUE); - if(m_TeamTypes.GetCount()==0) return; + if (m_TeamTypes.GetCount() == 0) { + return; + } CString str; str=GetText(&m_TeamTypes); TruncSpace(str); - CIniFileSection& sec=ini.sections[(char*)(LPCTSTR)str]; - sec.values["IonImmune"]=btos(m_IonImmune); + ini.SetBool(str, "IonImmune", m_IonImmune); } void CTeamTypes::OnTransportreturnsonunload() @@ -1071,14 +1056,15 @@ void CTeamTypes::OnTransportreturnsonunload() CIniFile& ini=Map->GetIniFile(); UpdateData(TRUE); - if(m_TeamTypes.GetCount()==0) return; + if (m_TeamTypes.GetCount() == 0) { + return; + } CString str; str=GetText(&m_TeamTypes); TruncSpace(str); - CIniFileSection& sec=ini.sections[(char*)(LPCTSTR)str]; - sec.values["TransportsReturnOnUnload"]=btos(m_TransportReturnsOnUnload); + ini.SetBool(str, "TransportsReturnOnUnload", m_TransportReturnsOnUnload); } void CTeamTypes::OnAreteammembersrecruitable() @@ -1086,14 +1072,15 @@ void CTeamTypes::OnAreteammembersrecruitable() CIniFile& ini=Map->GetIniFile(); UpdateData(TRUE); - if(m_TeamTypes.GetCount()==0) return; + if (m_TeamTypes.GetCount() == 0) { + return; + } CString str; str=GetText(&m_TeamTypes); TruncSpace(str); - CIniFileSection& sec=ini.sections[(char*)(LPCTSTR)str]; - sec.values["AreTeamMembersRecruitable"]=btos(m_AreTeamMembersRecruitable); + ini.SetBool(str, "AreTeamMembersRecruitable", m_AreTeamMembersRecruitable); } void CTeamTypes::OnIsbasedefense() @@ -1101,14 +1088,15 @@ void CTeamTypes::OnIsbasedefense() CIniFile& ini=Map->GetIniFile(); UpdateData(TRUE); - if(m_TeamTypes.GetCount()==0) return; + if (m_TeamTypes.GetCount() == 0) { + return; + } CString str; str=GetText(&m_TeamTypes); TruncSpace(str); - CIniFileSection& sec=ini.sections[(char*)(LPCTSTR)str]; - sec.values["IsBaseDefense"]=btos(m_IsBaseDefense); + ini.SetBool(str, "IsBaseDefense", m_IsBaseDefense); } void CTeamTypes::OnOnlytargethouseenemy() @@ -1116,14 +1104,15 @@ void CTeamTypes::OnOnlytargethouseenemy() CIniFile& ini=Map->GetIniFile(); UpdateData(TRUE); - if(m_TeamTypes.GetCount()==0) return; + if (m_TeamTypes.GetCount() == 0) { + return; + } CString str; str=GetText(&m_TeamTypes); TruncSpace(str); - CIniFileSection& sec=ini.sections[(char*)(LPCTSTR)str]; - sec.values["OnlyTargetHouseEnemy"]=btos(m_OnlyTargetHouseEnemy); + ini.SetBool(str, "IsBaseDefense", m_OnlyTargetHouseEnemy); } CString GetFree(const char* section); @@ -1132,44 +1121,46 @@ void CTeamTypes::OnNewteamtype() { CIniFile& ini=Map->GetIniFile(); - CString id=GetFreeID() ; + CString id=GetFreeID(); CString p; p=GetFree("TeamTypes"); - - ini.sections["TeamTypes"].values[p]=id; - CIniFileSection& s=ini.sections[id]; - s.values["Name"]="New teamtype"; - s.values["VeteranLevel"]="1"; - s.values["Loadable"]="no"; - s.values["Full"]="yes"; - s.values["Annoyance"]="no"; - s.values["GuardSlower"]="no"; - s.values["Recruiter"]="no"; - s.values["Autocreate"]="yes"; - s.values["Prebuild"]="no"; - s.values["Reinforce"]="no"; - s.values["Droppod"]="no"; - s.values["Whiner"]="no"; - s.values["LooseRecruit"]="no"; - s.values["Aggressive"]="no"; - s.values["Suicide"]="no"; - s.values["Priority"]="5"; - s.values["Max"]="5"; - s.values["TechLevel"]="0"; - s.values["Group"]="-1"; - s.values["OnTransOnly"]="no"; - s.values["AvoidThreats"]="no"; - s.values["IonImmune"]="no"; - s.values["TransportsReturnOnUnload"]="no"; - s.values["AreTeamMembersRecruitable"]="no"; - s.values["IsBaseDefense"]="no"; - s.values["OnlyTargetHouseEnemy"]="no"; + // TODO: change default value + ini.SetString("TeamTypes", p, id); + CIniFileSection& s = ini.AddSection(id); + s.SetString("Name", "New teamtype"); + s.SetInteger("VeteranLevel", 1); + s.SetBool("Loadable", false); + s.SetBool("Full", true); + s.SetBool("Annoyance", false); + s.SetBool("GuardSlower", false); + s.SetBool("Recruiter", false); + s.SetBool("Autocreate", true); + s.SetBool("Prebuild", false); + s.SetBool("Reinforce", false); + s.SetBool("Droppod", false); + s.SetBool("Whiner", false); + s.SetBool("LooseRecruit", false); + s.SetBool("Aggressive", false); + s.SetBool("Suicide", false); + s.SetInteger("Priority", 5); + s.SetInteger("Max", 5); + s.SetInteger("TechLevel", 0); + s.SetInteger("Group", -1); + s.SetBool("OnTransOnly", false); + s.SetBool("AvoidThreats", false); + s.SetBool("IonImmune", false); + s.SetBool("TransportsReturnOnUnload", false); + s.SetBool("AreTeamMembersRecruitable", false); + s.SetBool("IsBaseDefense", false); + s.SetBool("OnlyTargetHouseEnemy", false); #ifdef RA2_MODE - s.values["UseTransportOrigin"]="no"; - if(yuri_mode) s.values["MindControlDecision"]="0"; - + s.SetBool("UseTransportOrigin", false); + if (yuri_mode) { + s.SetInteger("MindControlDecision", 0); + } + #endif @@ -1209,20 +1200,22 @@ void CTeamTypes::OnEditchangeTag() CIniFile& ini=Map->GetIniFile(); UpdateData(TRUE); - if(m_TeamTypes.GetCount()==0) return; + if (m_TeamTypes.GetCount() == 0) { + return; + } CString str; str=GetText(&m_TeamTypes); TruncSpace(str); - CIniFileSection& sec=ini.sections[(char*)(LPCTSTR)str]; - + auto sec = ini.TryGetSection(str); + ASSERT(sec != nullptr); TruncSpace(m_Tag); - sec.values["Tag"]=m_Tag; - if(m_Tag==GetLanguageStringACP("None") || m_Tag.GetLength()==0) - { - sec.values.erase("Tag"); + if (m_Tag == GetLanguageStringACP("None") || m_Tag.IsEmpty()) { + sec->RemoveByKey("Tag"); + } else { + sec->SetString("Tag", m_Tag); } } @@ -1240,24 +1233,22 @@ void CTeamTypes::OnEditchangeTransportwaypoint() CIniFile& ini=Map->GetIniFile(); UpdateData(TRUE); - if(m_TeamTypes.GetCount()==0) return; + if (m_TeamTypes.GetCount() == 0) { + return; + } CString str; str=GetText(&m_TeamTypes); TruncSpace(str); - CIniFileSection& sec=ini.sections[(char*)(LPCTSTR)str]; - - if(strlen(m_TransportWaypoint)==0 || isSame(m_TransportWaypoint, TranslateStringACP("None"))) - { - sec.values.erase("TransportWaypoint"); - sec.values["UseTransportOrigin"]="no"; + auto sec = ini.TryGetSection(str); + ASSERT(sec != nullptr); + if (strlen(m_TransportWaypoint) == 0 || isSame(m_TransportWaypoint, TranslateStringACP("None"))) { + sec->RemoveByKey("TransportWaypoint"); + sec->SetBool("UseTransportOrigin", false); + return; } - else - { - sec.values["TransportWaypoint"]=GetWaypoint(atoi(m_TransportWaypoint)); - sec.values["UseTransportOrigin"]="yes"; - } - + sec->SetString("TransportWaypoint", GetWaypoint(atoi(m_TransportWaypoint))); + sec->SetBool( "UseTransportOrigin", true); } void CTeamTypes::OnKillfocusTransportwaypoint() @@ -1270,16 +1261,18 @@ void CTeamTypes::OnEditchangeMindcontroldecision() CIniFile& ini=Map->GetIniFile(); UpdateData(TRUE); - if(m_TeamTypes.GetCount()==0) return; + if (m_TeamTypes.GetCount() == 0) { + return; + } CString str; str=GetText(&m_TeamTypes); TruncSpace(str); - CIniFileSection& sec=ini.sections[(char*)(LPCTSTR)str]; - + auto sec = ini.TryGetSection(str); + ASSERT(sec != nullptr); CString tmp=m_MindControlDecision; TruncSpace(tmp); - sec.values["MindControlDecision"]=tmp; + sec->SetString("MindControlDecision", std::move(tmp)); } void CTeamTypes::OnKillfocusMindcontroldecision() diff --git a/MissionEditor/TerrainDlg.cpp b/MissionEditor/TerrainDlg.cpp index 8e557f1..54b3196 100644 --- a/MissionEditor/TerrainDlg.cpp +++ b/MissionEditor/TerrainDlg.cpp @@ -130,27 +130,31 @@ void CTerrainDlg::Update() { int i; int tilecount = 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++) + 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()) + auto const pSec = tiles->TryGetSection(sec); + + if (!pSec) { break; - if (atoi(tiles->sections[sec].values["TilesInSet"]) == 0) + } + if (pSec->GetInteger("TilesInSet") == 0) { continue; + } CString string; string = tset; string += " ("; - string += TranslateStringACP(tiles->sections[sec].values["SetName"]); + string += TranslateStringACP(pSec->GetString("SetName")); string += ")"; BOOL bForced = FALSE; @@ -158,22 +162,24 @@ void CTerrainDlg::Update() // force yes - CString datsec = (CString)"UseSet" + Map->GetTheater(); + auto const& theaterType = Map->GetTheater(); auto tsetc = CString(std::to_string(atoi(tset)).c_str()); - if (g_data.sections[datsec].FindValue(tsetc) >= 0) + if (g_data["UseSet" + theaterType].HasValue(tsetc)) { bForced = TRUE; + } // force no - datsec = (CString)"IgnoreSet" + Map->GetTheater(); - if (g_data.sections[datsec].FindValue(tsetc) >= 0) + if (g_data["IgnoreSet" + theaterType].HasValue(tsetc)) { bForcedNot = TRUE; + } - if (bForced || (!bForcedNot && (*tiledata)[tilecount].bAllowToPlace && !(*tiledata)[tilecount].bMarbleMadness)) + if (bForced || (!bForcedNot && (*tiledata)[tilecount].bAllowToPlace && !(*tiledata)[tilecount].bMarbleMadness)) { TileSet->SetItemData(TileSet->AddString(string), i); + } - tilecount += atoi(tiles->sections[sec].values["TilesInSet"]); + tilecount += tiles->GetInteger(sec, "TilesInSet"); } TileSet->SetCurSel(0); @@ -185,36 +191,34 @@ void CTerrainDlg::Update() while (Overlays->DeleteString(0) != CB_ERR); - int i; int e = 0; - for (i = 0;i < rules.sections["OverlayTypes"].values.size();i++) - { - CString id = *rules.sections["OverlayTypes"].GetValue(i); + auto const& types = rules["OverlayTypes"]; + for (auto i = 0; i < types.Size(); i++) { + CString id = types.Nth(i).second; id.TrimLeft(); id.TrimRight(); - if (id.GetLength() > 0) - { + if (id.GetLength() > 0) { - if (rules.sections.find(id) != rules.sections.end() && rules.sections[id].FindName("Name") >= 0) - { + if (rules[id].Exists("Name")) { int p; BOOL bListIt = TRUE; - for (p = 0;p < max_ovrl_img;p++) - if (ovrlpics[i][p] != NULL && ovrlpics[i][p]->pic != NULL) + for (p = 0; p < max_ovrl_img; p++) { + if (ovrlpics[i][p] != NULL && ovrlpics[i][p]->pic != NULL) { bListIt = TRUE; - + } + } #ifdef RA2_MODE if ((i >= 39 && i <= 60) || (i >= 180 && i <= 201) || i == 239 || i == 178 || i == 167 || i == 126 - || (i >= 122 && i <= 125)) + || (i >= 122 && i <= 125)) { bListIt = FALSE; + } #endif - if (bListIt) - { + if (bListIt) { CString str; - str = TranslateStringACP(rules.sections[(*rules.sections["OverlayTypes"].GetValue(i))].values["Name"]); + str = TranslateStringACP(rules.GetString(id, "Name")); Overlays->SetItemData(Overlays->AddString(str), e); } } @@ -228,26 +232,29 @@ DWORD CTerrainDlg::GetTileID(DWORD dwTileSet, int iTile) { int i, e; DWORD tilecount = 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++) + 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()) + auto const pSec = tiles->TryGetSection(sec); + if (!pSec) { return 0xFFFFFFFF; + } - - for (e = 0;e < atoi(tiles->sections[sec].values["TilesInSet"]);e++) - { - if (i == dwTileSet && e == iTile) + auto const tilesInset = pSec->GetInteger("TilesInSet"); + for (e = 0; e < tilesInset; e++) { + if (i == dwTileSet && e == iTile) { return tilecount; + } tilecount++; } diff --git a/MissionEditor/TileSetBrowserView.cpp b/MissionEditor/TileSetBrowserView.cpp index 6b794d2..a9e1182 100644 --- a/MissionEditor/TileSetBrowserView.cpp +++ b/MissionEditor/TileSetBrowserView.cpp @@ -381,23 +381,25 @@ DWORD CTileSetBrowserView::GetTileID(DWORD dwTileSet, DWORD dwType) { int i, e; DWORD tilecount = 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++) + 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()) + auto const pSec = tiles->TryGetSection(sec); + if (!pSec) { return 0xFFFFFFFF; + } - - for (e = 0;e < atoi(tiles->sections[sec].values["TilesInSet"]);e++) + auto const tilesInSet = pSec->GetInteger("TilesInSet"); + for (e = 0; e < tilesInSet; e++) { if (i == dwTileSet && e == dwType) return tilecount; @@ -421,8 +423,9 @@ void CTileSetBrowserView::SetTileSet(DWORD dwTileSet, BOOL bOnlyRedraw) CString tset; int e; - for (e = 0;e < 4 - strlen(currentTileSet);e++) + for (e = 0; e < 4 - strlen(currentTileSet); e++) { tset += "0"; + } tset += currentTileSet; @@ -430,7 +433,7 @@ void CTileSetBrowserView::SetTileSet(DWORD dwTileSet, BOOL bOnlyRedraw) m_tile_height = 0; int i; - int max = atoi(tiles->sections[(CString)"TileSet" + tset].values["TilesInSet"]); + int max = tiles->GetInteger("TileSet" + tset, "TilesInSet"); DWORD dwStartID = GetTileID(dwTileSet, 0); if ((*tiledata)[dwStartID].wTileCount && (*tiledata)[dwStartID].tiles[0].pic) { @@ -447,16 +450,11 @@ void CTileSetBrowserView::SetTileSet(DWORD dwTileSet, BOOL bOnlyRedraw) ((CFinalSunDlg*)theApp.m_pMainWnd)->m_view.m_isoview->m_BrushSize_x = 1; ((CFinalSunDlg*)theApp.m_pMainWnd)->m_view.m_isoview->m_BrushSize_y = 1; - int i; - for (i = 0;i < g_data.sections["StdBrushSize"].values.size();i++) - { - CString n = *g_data.sections["StdBrushSize"].GetValueName(i); - if ((*tiles).sections["General"].FindName(n) >= 0) - { - int tset = atoi((*tiles).sections["General"].values[n]); - if (tset == m_currentTileSet) - { - int bs = atoi(*g_data.sections["StdBrushSize"].GetValue(i)); + for (auto const& [n, val] : g_data["StdBrushSize"]) { + if (tiles->GetSection("General").Exists(n)) { + int tset = tiles->GetInteger("General", n); + if (tset == m_currentTileSet) { + int bs = atoi(val); ((CFinalSunDlg*)theApp.m_pMainWnd)->m_settingsbar.m_BrushSize = bs - 1; ((CFinalSunDlg*)theApp.m_pMainWnd)->m_settingsbar.UpdateData(FALSE); ((CFinalSunDlg*)theApp.m_pMainWnd)->m_view.m_isoview->m_BrushSize_x = bs; @@ -810,16 +808,11 @@ void CTileSetBrowserView::OnLButtonDown(UINT nFlags, CPoint point) ((CFinalSunDlg*)theApp.m_pMainWnd)->m_view.m_isoview->m_BrushSize_x = 1; ((CFinalSunDlg*)theApp.m_pMainWnd)->m_view.m_isoview->m_BrushSize_y = 1; - int i; - for (i = 0;i < g_data.sections["StdBrushSize"].values.size();i++) - { - CString n = *g_data.sections["StdBrushSize"].GetValueName(i); - if ((*tiles).sections["General"].FindName(n) >= 0) - { - int tset = atoi((*tiles).sections["General"].values[n]); - if (tset == m_currentTileSet) - { - int bs = atoi(*g_data.sections["StdBrushSize"].GetValue(i)); + for (auto const& [n, val] : g_data["StdBrushSize"]) { + if (tiles->GetSection("General").Exists(n)) { + int tset = tiles->GetInteger("General", n); + if (tset == m_currentTileSet) { + int bs = atoi(val); ((CFinalSunDlg*)theApp.m_pMainWnd)->m_settingsbar.m_BrushSize = bs - 1; ((CFinalSunDlg*)theApp.m_pMainWnd)->m_settingsbar.UpdateData(FALSE); ((CFinalSunDlg*)theApp.m_pMainWnd)->m_view.m_isoview->m_BrushSize_x = bs; @@ -938,7 +931,7 @@ void CTileSetBrowserView::SetOverlay(DWORD dwID) } if (!bFound) { - theApp.m_loading->LoadOverlayGraphic(*rules.sections["OverlayTypes"].GetValue(dwID), dwID); + theApp.m_loading->LoadOverlayGraphic(rules["OverlayTypes"].Nth(dwID).second, dwID); ((CFinalSunDlg*)(theApp.m_pMainWnd))->m_view.m_isoview->UpdateOverlayPictures(); //p=ovrlpics[dwID][k]; } diff --git a/MissionEditor/TipDlg.cpp b/MissionEditor/TipDlg.cpp index 164d433..aa19fa0 100644 --- a/MissionEditor/TipDlg.cpp +++ b/MissionEditor/TipDlg.cpp @@ -65,13 +65,13 @@ CTipDlg::CTipDlg(CWnd* pParent /*=NULL*/) optini.LoadFile(iniFile); CWinApp* pApp = AfxGetApp(); - m_bStartup = !atoi(optini.sections[szSection].values[szIntStartup]); - UINT iFilePos = atoi(optini.sections[szSection].values[szIntFilePos]); + m_bStartup = !optini.GetBool(szSection, szIntStartup); + UINT iFilePos = optini.GetInteger(szSection, szIntFilePos); // try top open the tips file CString tipsfile=AppPath; tipsfile+="\\tips."; - tipsfile+=language.sections[theApp.m_Options.LanguageName+"Header"].values["ExtensionName"]; + tipsfile += language.GetString(theApp.m_Options.LanguageName + "Header", "ExtensionName"); m_pStream = fopen(tipsfile, "r"); if (m_pStream == NULL) @@ -85,20 +85,15 @@ CTipDlg::CTipDlg(CWnd* pParent /*=NULL*/) _fstat(_fileno(m_pStream), &buf); CString strCurrentTime = ctime(&buf.st_ctime); strCurrentTime.TrimRight(); - CString strStoredTime = optini.sections[szSection].values[szTimeStamp]; - if (strCurrentTime != strStoredTime) - { + auto const& strStoredTime = optini.GetString(szSection, szTimeStamp); + if (strCurrentTime != strStoredTime) { iFilePos = 0; - optini.sections[szSection].values[szTimeStamp]=(LPCTSTR)strCurrentTime; - + optini.SetString(szSection, szTimeStamp, strCurrentTime); } - if (fseek(m_pStream, iFilePos, SEEK_SET) != 0) - { + if (fseek(m_pStream, iFilePos, SEEK_SET) != 0) { AfxMessageBox(GetLanguageStringACP("CG_IDP_FILE_CORRUPT")); - } - else - { + } else { GetNextTipString(m_strTip); } @@ -121,9 +116,7 @@ CTipDlg::~CTipDlg() #endif optini.LoadFile(iniFile); - char val[50]; - itoa(ftell(m_pStream),val, 10); - optini.sections[szSection].values[szIntFilePos]=val; + optini.SetInteger(szSection, szIntFilePos, ftell(m_pStream)); optini.SaveFile(iniFile); fclose(m_pStream); } @@ -203,10 +196,7 @@ void CTipDlg::OnOK() #endif optini.LoadFile(iniFile); - - char val[50]; - itoa(!m_bStartup,val, 10); - optini.sections[szSection].values[szIntStartup]=val; + optini.SetBool(szSection, szIntStartup, !m_bStartup); optini.SaveFile(iniFile); } diff --git a/MissionEditor/TriggerActionsDlg.cpp b/MissionEditor/TriggerActionsDlg.cpp index 3a45083..9cdbd67 100644 --- a/MissionEditor/TriggerActionsDlg.cpp +++ b/MissionEditor/TriggerActionsDlg.cpp @@ -103,7 +103,7 @@ void CTriggerActionsDlg::OnSelchangeAction() int i; CString ActionData; - ActionData=ini.sections["Actions"].values[(LPCTSTR)m_currentTrigger]; + ActionData = ini.GetString("Actions", m_currentTrigger); int startpos=1+curev*8; CString ActionType=GetParam(ActionData,startpos); @@ -153,15 +153,20 @@ void CTriggerActionsDlg::OnEditchangeActiontype() int pos=1+8*curev; - ini.sections["Actions"].values[(LPCTSTR)m_currentTrigger]=SetParam(ini.sections["Actions"].values[(LPCTSTR)m_currentTrigger], pos, (LPCTSTR)eventtype); + ini.SetString("Actions",m_currentTrigger, SetParam(ini.GetString("Actions", m_currentTrigger), pos, (LPCTSTR)eventtype)); - if(g_data.sections[acsec].FindName(eventtype)<0) return; + auto const& eventDef = g_data[acsec][eventtype]; + if (eventDef.IsEmpty()) { + return; + } - eventdata=g_data.sections[acsec].values[eventtype]; + eventdata = eventDef; #ifdef RA2_MODE - if(g_data.sections["ActionsRA2"].FindName(eventtype)>=0) - eventdata=g_data.sections["ActionsRA2"].values[eventtype]; + auto const& ra2Def = g_data["ActionsRA2"][eventtype]; + if (!ra2Def.IsEmpty()) { + eventdata = ra2Def; + } #endif CString desc=GetParam(eventdata,10); @@ -179,57 +184,64 @@ void CTriggerActionsDlg::OnEditchangeActiontype() int pListType[6]; memset(pListType, 0, 6*sizeof(int)); - if(atoi(ptype[0])>=0) pListType[0]=atoi(GetParam(g_data.sections["ParamTypes"].values[ptype[0]], 1)); - if(atoi(ptype[1])>=0) pListType[1]=atoi(GetParam(g_data.sections["ParamTypes"].values[ptype[1]], 1)); - if(atoi(ptype[2])>=0) pListType[2]=atoi(GetParam(g_data.sections["ParamTypes"].values[ptype[2]], 1)); - if(atoi(ptype[3])>=0) pListType[3]=atoi(GetParam(g_data.sections["ParamTypes"].values[ptype[3]], 1)); - if(atoi(ptype[4])>=0) pListType[4]=atoi(GetParam(g_data.sections["ParamTypes"].values[ptype[4]], 1)); - if(atoi(ptype[5])>=0) pListType[5]=atoi(GetParam(g_data.sections["ParamTypes"].values[ptype[5]], 1)); + if (atoi(ptype[0]) >= 0) { + pListType[0] = atoi(GetParam(g_data.GetString("ParamTypes", ptype[0]), 1)); + } + if (atoi(ptype[1]) >= 0) { + pListType[1] = atoi(GetParam(g_data.GetString("ParamTypes", ptype[1]), 1)); + } + if (atoi(ptype[2]) >= 0) { + pListType[2] = atoi(GetParam(g_data.GetString("ParamTypes", ptype[2]), 1)); + } + if (atoi(ptype[3]) >= 0) { + pListType[3] = atoi(GetParam(g_data.GetString("ParamTypes", ptype[3]), 1)); + } + if (atoi(ptype[4]) >= 0) { + pListType[4] = atoi(GetParam(g_data.GetString("ParamTypes", ptype[4]), 1)); + } + if (atoi(ptype[5]) >= 0) { + pListType[5] = atoi(GetParam(g_data.GetString("ParamTypes", ptype[5]), 1)); + } - int i; - for(i=0;i<6;i++) - { + for (auto i = 0; i < 6; i++) { + if (atoi(ptype[i]) > 0) { + CString paramname = GetParam(g_data.GetString("ParamTypes", ptype[i]), 0); - if(atoi(ptype[i])>0) - { - CString paramname=GetParam(g_data.sections["ParamTypes"].values[ptype[i]], 0); - m_Parameter.SetItemData(m_Parameter.AddString(paramname), i); - } - else if(atoi(ptype[i])<0) - { + } else if (atoi(ptype[i]) < 0) { char c[50]; - itoa(-atoi(ptype[i]),c,10); - ini.sections["Actions"].values[(LPCTSTR)m_currentTrigger]=SetParam(ini.sections["Actions"].values[(LPCTSTR)m_currentTrigger], pos+i+1,c ); + itoa(-atoi(ptype[i]), c, 10); + ini.SetString("Actions", m_currentTrigger, SetParam(ini["Actions"][m_currentTrigger], pos + i + 1, c)); + } else { + ini.SetString("Actions", m_currentTrigger, SetParam(ini["Actions"][m_currentTrigger], pos + i + 1, "0")); } - else - { - ini.sections["Actions"].values[(LPCTSTR)m_currentTrigger]=SetParam(ini.sections["Actions"].values[(LPCTSTR)m_currentTrigger], pos+i+1, "0"); - } - } // MW fix for waypoint/number issue CString code; BOOL bNoWP=FALSE; - code=GetParam(ini.sections["Actions"].values[(LPCTSTR)m_currentTrigger], pos+1); - if(g_data.sections["DontSaveAsWP"].FindValue(code)>=0) bNoWP=TRUE; + code = GetParam(ini["Actions"][m_currentTrigger], pos + 1); + if (g_data["DontSaveAsWP"].HasValue(code)) { + bNoWP = TRUE; + } // conversion below: - if(IsWaypointFormat(GetParam(ini.sections["Actions"].values[(LPCTSTR)m_currentTrigger], pos+1+6)) && bNoWP) - { - int number=GetWaypoint(GetParam(ini.sections["Actions"].values[(LPCTSTR)m_currentTrigger], pos+1+6)); + if (IsWaypointFormat( + GetParam(ini["Actions"][m_currentTrigger], pos + 1 + 6) + ) + && bNoWP) { + int number = GetWaypoint(GetParam(ini["Actions"][m_currentTrigger], pos + 1 + 6)); char c[50]; itoa(number, c, 10); - ini.sections["Actions"].values[(LPCTSTR)m_currentTrigger]=SetParam(ini.sections["Actions"].values[(LPCTSTR)m_currentTrigger], pos+1+6, c); - } - else if(!IsWaypointFormat(GetParam(ini.sections["Actions"].values[(LPCTSTR)m_currentTrigger], pos+1+6)) && !bNoWP) - { - int wp=atoi(GetParam(ini.sections["Actions"].values[(LPCTSTR)m_currentTrigger], pos+1+6)); - CString s=GetWaypoint(wp); - ini.sections["Actions"].values[(LPCTSTR)m_currentTrigger]=SetParam(ini.sections["Actions"].values[(LPCTSTR)m_currentTrigger], pos+1+6, s); - - } + ini.SetString("Actions", m_currentTrigger, SetParam(ini["Actions"][m_currentTrigger], pos + 1 + 6, c)); + } else if (!IsWaypointFormat( + GetParam(ini["Actions"][m_currentTrigger], pos + 1 + 6) + ) + && !bNoWP) { + int wp = atoi(GetParam(ini["Actions"][m_currentTrigger], pos + 1 + 6)); + CString s = GetWaypoint(wp); + ini.SetString("Actions", m_currentTrigger, SetParam(ini["Actions"][m_currentTrigger], pos + 1 + 6, s)); + }; if(atoi(GetParam(eventdata, 7))==1) @@ -269,8 +281,7 @@ void CTriggerActionsDlg::OnSelchangeParameter() - CString ActionData; - ActionData=ini.sections["Actions"].values[(LPCTSTR)m_currentTrigger]; + auto const& ActionData = ini["Actions"][m_currentTrigger]; int startpos=1+curev*8; @@ -278,37 +289,32 @@ void CTriggerActionsDlg::OnSelchangeParameter() CString code; BOOL bNoWP=FALSE; code=GetParam(ActionData, startpos+1); - if(g_data.sections["DontSaveAsWP"].FindValue(code)>=0) bNoWP=TRUE; + if (g_data["DontSaveAsWP"].HasValue(code)) { + bNoWP = TRUE; + } - if(curparam>=0 && curparam<6) - { - CString ParamType=GetParam(g_data.sections["Actions"].values[GetParam(ActionData,startpos)],1+curparam); + if (curparam >= 0 && curparam < 6) { + CString ParamType = GetParam(g_data["Actions"][GetParam(ActionData, startpos)], 1 + curparam); #ifdef RA2_MODE - if(g_data.sections["ActionsRA2"].FindName(GetParam(ActionData, startpos))>=0) - { - ParamType=GetParam(g_data.sections["ActionsRA2"].values[GetParam(ActionData,startpos)],1+curparam); + if (g_data["ActionsRA2"].Exists(GetParam(ActionData, startpos))) { + ParamType = GetParam(g_data["ActionsRA2"][GetParam(ActionData, startpos)], 1 + curparam); } #endif - if(atoi(ParamType)<0) - { - } - else - { - CString ListType=GetParam(g_data.sections["ParamTypes"].values[ParamType],1); + if (atoi(ParamType) >= 0) { + CString ListType = GetParam(g_data["ParamTypes"][ParamType], 1); HandleParamList(m_ParamValue, atoi(ListType)); - m_ParamValue.SetWindowText(GetParam(ActionData,startpos+1+curparam)); - + m_ParamValue.SetWindowText(GetParam(ActionData, startpos + 1 + curparam)); + int i; - BOOL bFound=FALSE; - for(i=0;i=0) bNoWP=TRUE; + if (g_data["DontSaveAsWP"].HasValue(code)) { + bNoWP = TRUE; + } CString newVal; m_ParamValue.GetWindowText(newVal); @@ -393,20 +398,18 @@ void CTriggerActionsDlg::OnEditchangeParamvalue() if(newVal.Find(",",0)>=0) newVal.SetAt(newVal.Find(",",0), 0); - if(curparam>=0) - { - ini.sections["Actions"].values[(LPCTSTR)m_currentTrigger]=SetParam(ActionData, startpos+1+curparam, newVal); - } - else if(curparam==-1) // waypoint FIX MW: OR NUMBER!!! - { - int pos=1+8*curev+7; - + if(curparam>=0) { + ini.SetString("Actions", m_currentTrigger, SetParam(ActionData, startpos + 1 + curparam, newVal)); + // waypoint FIX MW: OR NUMBER!!! + } else if (curparam == -1) { + int pos = 1 + 8 * curev + 7; + CString waypoint = newVal; - CString waypoint=newVal; - - if(!bNoWP) waypoint=GetWaypoint(atoi(newVal)); - - ini.sections["Actions"].values[(LPCTSTR)m_currentTrigger]=SetParam(ini.sections["Actions"].values[(LPCTSTR)m_currentTrigger], pos, (LPCTSTR)waypoint); + if (!bNoWP) { + waypoint = GetWaypoint(atoi(newVal)); + } + + ini.SetString("Actions", m_currentTrigger, SetParam(ini["Actions"][m_currentTrigger], pos, (LPCTSTR)waypoint)); } } @@ -415,19 +418,21 @@ void CTriggerActionsDlg::OnNewaction() { CIniFile& ini=Map->GetIniFile(); - if(m_currentTrigger.GetLength()==0) return; + if (m_currentTrigger.GetLength() == 0) { + return; + } + // TODO: verify + auto& sec = ini.AddSection("Actions"); - CIniFileSection& sec=ini.sections["Actions"]; - - int cval=atoi(GetParam(sec.values[(LPCTSTR)m_currentTrigger],0)); + int cval = atoi(GetParam(sec.GetString(m_currentTrigger), 0)); cval++; char c[50]; itoa(cval,c,10); - sec.values[(LPCTSTR)m_currentTrigger]=SetParam(sec.values[(LPCTSTR)m_currentTrigger],0,c); - sec.values[(LPCTSTR)m_currentTrigger]+=",0,0,0,0,0,0,0,A"; - + auto action = SetParam(sec.GetString(m_currentTrigger), 0, c); + action += ",0,0,0,0,0,0,0,A"; + sec.SetString(m_currentTrigger, action); UpdateDialog(); @@ -446,10 +451,11 @@ void CTriggerActionsDlg::OnDeleteaction() if(MessageBox("Do you really want to delete this action?","Delete action", MB_YESNO)==IDNO) return; - CIniFileSection& sec=ini.sections["Actions"]; + auto sec = ini.TryGetSection("Actions"); + ASSERT(sec != nullptr); CString data; - data=sec.values[(LPCTSTR)m_currentTrigger]; + data = sec->GetString(m_currentTrigger); int v=atoi(GetParam(data,0)); char c[50]; @@ -460,8 +466,9 @@ void CTriggerActionsDlg::OnDeleteaction() int pos=1+curev*8; int posc=1+v*8; int i; - for(i=0;i<8;i++) - data=SetParam(data,pos+i, GetParam(data,posc+i)); + for (i = 0; i < 8; i++) { + data = SetParam(data, pos + i, GetParam(data, posc + i)); + } // MW April 17th, 2002: // fixed: (char*)(LPCTSTR)data should not be modified directly, @@ -480,7 +487,7 @@ void CTriggerActionsDlg::OnDeleteaction() } //MessageBox(str_act); - sec.values[(LPCTSTR)m_currentTrigger]=str_act; + sec->SetString(m_currentTrigger, str_act); delete[] str_act; UpdateDialog(); @@ -508,23 +515,19 @@ void CTriggerActionsDlg::UpdateDialog() while(m_ActionType.DeleteString(0)!=CB_ERR); int i; - for(i=0;i=0) + if(g_data.sections["ActionsRA2"].FindIndex(eventid)>=0) eventdata=g_data.sections["ActionsRA2"].values[eventid]; #endif*/ - CString text=eventid+" "+GetParam(eventdata,0); - text.Replace("%1",","); + CString text = eventid + " " + GetParam(eventdata, 0); + text.Replace("%1", ","); #ifdef RA2_MODE - if(GetParam(eventdata,12)=="1" && (yuri_mode || !isTrue(GetParam(eventdata, 14)))) - { + if (GetParam(eventdata, 12) == "1" && (yuri_mode || !isTrue(GetParam(eventdata, 14)))) { #else - if(GetParam(eventdata,11)=="1") - { + if (GetParam(eventdata, 11) == "1") { #endif m_ActionType.AddString(text); } @@ -533,17 +536,16 @@ void CTriggerActionsDlg::UpdateDialog() int cur_sel=m_Action.GetCurSel(); while(m_Action.DeleteString(0)!=CB_ERR); - CString Data=ini.sections["Actions"].values[m_currentTrigger]; - int count=atoi(GetParam(Data,0)); + auto const& Data = ini["Actions"][m_currentTrigger]; + int count = atoi(GetParam(Data, 0)); - for(i=0;i=m_Trigger.GetCount()) curData=m_Trigger.GetCount()-1; + if (curData < 0) { + curData = 0; + } + if (curData >= m_Trigger.GetCount()) { + curData = m_Trigger.GetCount() - 1; + } - if(ini.sections["Triggers"].values.size()) m_Trigger.SetCurSel(0); + if (ini["Triggers"].Size()) { + m_Trigger.SetCurSel(0); + } for(i=0;iGetIniFile(); CString ID_T=GetFreeID(); - ini.sections["Triggers"].values[ID_T]=Map->GetHouseID(0, TRUE)+",,New trigger,0,1,1,1,0"; - ini.sections["Events"].values[ID_T]="0"; - ini.sections["Actions"].values[ID_T]="0"; + ini.SetString("Triggers", ID_T, Map->GetHouseID(0, TRUE) + ",,New trigger,0,1,1,1,0"); + ini.SetString("Events", ID_T, "0"); + ini.SetString("Actions", ID_T, "0"); //if(MessageBox("Trigger created. If you want to create a simple tag now, press Yes. The tag will be called ""New tag"", you should name it like the trigger (after you have set up the trigger).","Trigger created",MB_YESNO)) { CString ID_TAG=GetFreeID(); - ini.sections["Tags"].values[ID_TAG]="0,New tag,"; - ini.sections["Tags"].values[ID_TAG]+=ID_T; + ini.SetString("Tags",ID_TAG, "0,New tag," + ID_T); } ((CFinalSunDlg*)theApp.m_pMainWnd)->UpdateDialogs(TRUE); - int i; - for(i=0;i keysToDelete; + for (auto const& [type, def] : ini["Tags"]) { + auto const attTrigg = GetParam(def, 2); + if (triggerId == attTrigg) { + keysToDelete.push_back(type); } - } + } + for (auto const& keyToDelete : keysToDelete) { + ini.RemoveValueByKey("Tags", keyToDelete); + } + } - } - - ini.sections["Triggers"].values.erase((LPCTSTR)trigger); - ini.sections["Events"].values.erase((LPCTSTR)trigger); - ini.sections["Actions"].values.erase((LPCTSTR)trigger); + ini.RemoveValueByKey("Triggers", triggerId); + ini.RemoveValueByKey("Events", triggerId); + ini.RemoveValueByKey("Actions", triggerId); ((CFinalSunDlg*)theApp.m_pMainWnd)->UpdateDialogs(TRUE); @@ -235,27 +236,38 @@ void CTriggerEditorDlg::OnEditchangeTrigger() CIniFile& ini=Map->GetIniFile(); int curSel=m_Trigger.GetCurSel(); - if(curSel<0) - { - m_TriggerOptions.m_currentTrigger=""; - if(m_TriggerOptions.m_hWnd) m_TriggerOptions.UpdateDialog(); - m_TriggerEvents.m_currentTrigger=""; - if(m_TriggerEvents.m_hWnd) m_TriggerEvents.UpdateDialog(); - m_TriggerActions.m_currentTrigger=""; - if(m_TriggerActions.m_hWnd) m_TriggerActions.UpdateDialog(); + if (curSel < 0) { + m_TriggerOptions.m_currentTrigger = ""; + if (m_TriggerOptions.m_hWnd) { + m_TriggerOptions.UpdateDialog(); + } + m_TriggerEvents.m_currentTrigger = ""; + if (m_TriggerEvents.m_hWnd) { + m_TriggerEvents.UpdateDialog(); + } + m_TriggerActions.m_currentTrigger = ""; + if (m_TriggerActions.m_hWnd) { + m_TriggerActions.UpdateDialog(); + } return; } int curInd=m_Trigger.GetItemData(curSel); - CString Trigger=*ini.sections["Triggers"].GetValueName(curInd); + auto const triggerId=ini["Triggers"].Nth(curInd).first; - m_TriggerOptions.m_currentTrigger=Trigger; - if(m_TriggerOptions.m_hWnd) m_TriggerOptions.UpdateDialog(); - m_TriggerEvents.m_currentTrigger=Trigger; - if(m_TriggerEvents.m_hWnd) m_TriggerEvents.UpdateDialog(); - m_TriggerActions.m_currentTrigger=Trigger; - if(m_TriggerActions.m_hWnd) m_TriggerActions.UpdateDialog(); + m_TriggerOptions.m_currentTrigger=triggerId; + if (m_TriggerOptions.m_hWnd) { + m_TriggerOptions.UpdateDialog(); + } + m_TriggerEvents.m_currentTrigger = triggerId; + if (m_TriggerEvents.m_hWnd) { + m_TriggerEvents.UpdateDialog(); + } + m_TriggerActions.m_currentTrigger = triggerId; + if (m_TriggerActions.m_hWnd) { + m_TriggerActions.UpdateDialog(); + } } void CTriggerEditorDlg::OnSelchangeTriggertab(NMHDR* pNMHDR, LRESULT* pResult) @@ -288,25 +300,21 @@ void CTriggerEditorDlg::OnPlaceonmap() CIniFile& ini=Map->GetIniFile(); int sel=m_Trigger.GetCurSel(); - if(sel<0) return; + if (sel < 0) { + return; + } + int curtrig=m_Trigger.GetItemData(sel); - - CString trigger=*ini.sections["Triggers"].GetValueName(curtrig); - - int i; + auto const triggerId = ini["Triggers"].Nth(curtrig).first; CString tag; - for(i=0;iGetIniFile(); int sel=m_Trigger.GetCurSel(); - if(sel<0) return; + if (sel < 0) { + return; + } int curtrig=m_Trigger.GetItemData(sel); - CString trigger=*ini.sections["Triggers"].GetValueName(curtrig); + auto const& triggerId = ini["Triggers"].Nth(curtrig).first; - CString ID_T=GetFreeID(); - ini.sections["Triggers"].values[ID_T]=ini.sections["Triggers"].values[trigger]; - ini.sections["Events"].values[ID_T]=ini.sections["Events"].values[trigger]; - ini.sections["Actions"].values[ID_T]=ini.sections["Actions"].values[trigger]; + CString newId = GetFreeID(); + ini.SetString("Triggers", newId, ini["Triggers"][triggerId]); + ini.SetString("Events", newId, ini["Events"][triggerId]); + ini.SetString("Actions", newId, ini["Actions"][triggerId]); - ini.sections["Triggers"].values[ID_T]=SetParam(ini.sections["Triggers"].values[ID_T], 2, GetParam(ini.sections["Triggers"].values[ID_T], 2) + " Clone"); + ini.SetString("Triggers", newId, SetParam(ini["Triggers"][newId], 2, GetParam(ini["Triggers"][newId], 2) + " Clone")); { - CString ID_TAG=GetFreeID(); - ini.sections["Tags"].values[ID_TAG]=(CString)"0,"+GetParam(ini.sections["Triggers"].values[ID_T], 2)+","; - ini.sections["Tags"].values[ID_TAG]+=ID_T; + CString newTagId = GetFreeID(); + ini.SetString("Tags", newTagId, "0," + GetParam(ini["Triggers"][newId], 2) + ","); + ini.SetString("Tags", newTagId, newId); } ((CFinalSunDlg*)theApp.m_pMainWnd)->UpdateDialogs(TRUE); - int i; - for(i=0;i=count) return -1; @@ -102,18 +102,20 @@ void CTriggerEventsDlg::OnNewevent() { CIniFile& ini=Map->GetIniFile(); - if(m_currentTrigger.GetLength()==0) return; + if (m_currentTrigger.GetLength() == 0) { + return; + } - CIniFileSection& sec=ini.sections["Events"]; + CIniFileSection& sec=ini.AddSection("Events"); - int cval=atoi(GetParam(sec.values[(LPCTSTR)m_currentTrigger],0)); + int cval = atoi(GetParam(sec.GetString(m_currentTrigger), 0)); cval++; char c[50]; itoa(cval,c,10); - sec.values[(LPCTSTR)m_currentTrigger]=SetParam(sec.values[(LPCTSTR)m_currentTrigger],0,c); - sec.values[(LPCTSTR)m_currentTrigger]+=",0,0,0"; + sec.SetString(m_currentTrigger, SetParam(sec[m_currentTrigger], 0, c)); + sec.SetString(m_currentTrigger, ",0,0,0"); UpdateDialog(); @@ -152,20 +154,21 @@ void CTriggerEventsDlg::OnDeleteevent() //MessageBox(d); CIniFile& ini=Map->GetIniFile(); - if(m_currentTrigger.GetLength()==0) return; + if (m_currentTrigger.GetLength() == 0) { + return; + } int sel2=m_Event.GetCurSel(); - if(sel2<0) return; + if (sel2 < 0) { + return; + } int curev=m_Event.GetItemData(sel2); - if(MessageBox("Do you really want to delete this event?","Delete event", MB_YESNO)==IDNO) return; + if (MessageBox("Do you really want to delete this event?", "Delete event", MB_YESNO) == IDNO) { + return; + } - - CIniFileSection& sec=ini.sections["Events"]; - - CString data; - data=sec.values[(LPCTSTR)m_currentTrigger]; - - CString orig_data=data; + auto const & orig_data = ini["Events"][m_currentTrigger]; + CString data = orig_data; int v=atoi(GetParam(data,0)); char c[50]; @@ -183,15 +186,18 @@ void CTriggerEventsDlg::OnDeleteevent() BOOL bEvent1Needs4=FALSE; - if(GetParam(data, pos+1)=="2") bEvent1Needs4=TRUE; + if (GetParam(data, pos + 1) == "2") { + bEvent1Needs4 = TRUE; + } int count=3; - if(bEvent1Needs4) count=4; + if (bEvent1Needs4) { + count = 4; + } int del_start=FindTokenX(data, ',', pos); int del_end=FindTokenX(data, ',', pos+count); - if(del_end<0) - { + if (del_end < 0) { // beyond end, so delete all... del_end=data.GetLength(); @@ -216,7 +222,7 @@ void CTriggerEventsDlg::OnDeleteevent() } }*/ - sec.values[(LPCTSTR)m_currentTrigger]=data; + ini.SetString("Events", m_currentTrigger, data); UpdateDialog(); } @@ -225,27 +231,30 @@ void CTriggerEventsDlg::OnSelchangeEvent() { CIniFile& ini=Map->GetIniFile(); - if(m_currentTrigger.GetLength()==0) return; + if (m_currentTrigger.GetLength() == 0) { + return; + } int selev=m_Event.GetCurSel(); - if(selev<0) return; + if (selev < 0) { + return; + } int curev=m_Event.GetItemData(selev); int i; - CString EventData; - EventData=ini.sections["Events"].values[(LPCTSTR)m_currentTrigger]; + auto const& EventData = ini["Events"][m_currentTrigger]; int startpos=GetEventParamStart(EventData, curev); //1+curev*3; CString EventType=GetParam(EventData,startpos); m_EventType.SetWindowText(EventType); - for(i=0;iGetIniFile(); - if(m_currentTrigger.GetLength()==0) return; + if (m_currentTrigger.GetLength() == 0) { + return; + } int selev=m_Event.GetCurSel(); - if(selev<0) return; + if (selev < 0) { + return; + } int curev=m_Event.GetItemData(selev); CString e1,e2; @@ -268,19 +281,19 @@ void CTriggerEventsDlg::OnEditchangeEventtype() m_EventType.GetWindowText(eventtype); TruncSpace(eventtype); - if(eventtype.GetLength()==0) - { - eventtype="0"; + if (eventtype.GetLength() == 0) { + eventtype = "0"; m_EventType.SetWindowText(eventtype); } - int pos=GetEventParamStart(ini.sections["Events"].values[(LPCTSTR)m_currentTrigger], curev); //1+3*curev; + int pos = GetEventParamStart(ini["Events"][m_currentTrigger], curev); //1+3*curev; - BOOL bAlready4=FALSE; - if(atoi(GetParam(ini.sections["Events"].values[(LPCTSTR)m_currentTrigger], pos+1))==2) - bAlready4=TRUE; + BOOL bAlready4 = FALSE; + if (atoi(GetParam(ini["Events"][m_currentTrigger], pos + 1)) == 2) { + bAlready4 = TRUE; + } - ini.sections["Events"].values[(LPCTSTR)m_currentTrigger]=SetParam(ini.sections["Events"].values[(LPCTSTR)m_currentTrigger], pos, (LPCTSTR)eventtype); + ini.SetString("Events", m_currentTrigger, SetParam(ini["Events"][m_currentTrigger], pos, eventtype)); CString evsec="Events"; @@ -289,12 +302,16 @@ void CTriggerEventsDlg::OnEditchangeEventtype() #endif - if(g_data.sections[evsec].FindName(eventtype)<0) return; - eventdata=g_data.sections[evsec].values[eventtype]; + if (!g_data[evsec].Exists(eventtype)) { + return; + } + eventdata = g_data[evsec][eventtype]; #ifdef RA2_MODE - if(g_data.sections["EventsRA2"].FindName(eventtype)>=0) - eventdata=g_data.sections["EventsRA2"].values[eventtype]; + auto const ra2EventConf = g_data.GetString("EventsRA2", eventtype); + if (!ra2EventConf.IsEmpty()) { + eventdata = ra2EventConf; + } #endif CString desc=GetParam(eventdata,5); @@ -307,59 +324,51 @@ void CTriggerEventsDlg::OnEditchangeEventtype() int pListType[2]; - pListType[0]=atoi(GetParam(g_data.sections["ParamTypes"].values[ptype[0]], 1)); - pListType[1]=atoi(GetParam(g_data.sections["ParamTypes"].values[ptype[1]], 1)); + pListType[0]=atoi(GetParam(g_data["ParamTypes"][ptype[0]], 1)); + pListType[1]=atoi(GetParam(g_data["ParamTypes"][ptype[1]], 1)); - int code=atoi(GetParam(g_data.sections["ParamTypes"].values[ptype[0]], 2)); // usually 0 + int code = atoi(GetParam(g_data["ParamTypes"][ptype[0]], 2)); // usually 0 // ************************************** // MW ADD SUPPORT FOR 2 PARAMS+CODE - if(code==2) - { + if (code == 2) { // add code + event 0 ONLY IF THEY DO NOT ALREADY EXIST - if(!bAlready4) ini.sections["Events"].values[(LPCTSTR)m_currentTrigger]=SetParam(ini.sections["Events"].values[(LPCTSTR)m_currentTrigger], pos+1, "2,0"); - - } - else - { + if (!bAlready4) { + ini.SetString("Events", m_currentTrigger, SetParam(ini["Events"][m_currentTrigger], pos + 1, "2,0")); + } + } else { // remove code + event 0 char c[50]; itoa(code, c, 10); - ini.sections["Events"].values[(LPCTSTR)m_currentTrigger]=SetParam(ini.sections["Events"].values[(LPCTSTR)m_currentTrigger], pos+1, c); + ini.SetString("Events", m_currentTrigger, SetParam(ini["Events"][m_currentTrigger], pos + 1, c)); - if(bAlready4) - { - - CString& data=ini.sections["Events"].values[(LPCTSTR)m_currentTrigger]; - - int del_start=FindTokenX(data, ',', pos+2); - int del_end=FindTokenX(data, ',', pos+3); - if(del_end<0) - { + if (bAlready4) { + CString data = ini["Events"][m_currentTrigger]; + int del_start = FindTokenX(data, ',', pos + 2); + int del_end = FindTokenX(data, ',', pos + 3); + if (del_end < 0) { // beyond end, so delete all... - del_end=data.GetLength(); + del_end = data.GetLength(); } - data.Delete(del_start, del_end-del_start); + data.Delete(del_start, del_end - del_start); + ini.SetString("Events", m_currentTrigger, data); } } // ************************************** int i; - for(i=0;i<2;i++) - { - int add=0; - if(code==2) add=1; - - if(atoi(ptype[i])!=0 && atoi(ptype[i])>0 && atoi(ptype[i])!=47) - { - CString paramname=GetParam(g_data.sections["ParamTypes"].values[ptype[i]], 0); - - m_Parameter.SetItemData(m_Parameter.AddString(paramname), i+add); - } - - + for (i = 0; i < 2; i++) { + int add = 0; + if (code == 2) { + add = 1; + } + if (atoi(ptype[i]) != 0 && atoi(ptype[i]) > 0 && atoi(ptype[i]) != 47) { + CString paramname = GetParam(g_data["ParamTypes"][ptype[i]], 0); + + m_Parameter.SetItemData(m_Parameter.AddString(paramname), i + add); + } } m_ParamValue.SetWindowText(""); @@ -369,126 +378,127 @@ void CTriggerEventsDlg::OnEditchangeEventtype() } - - RepairTrigger(ini.sections["Triggers"].values[m_currentTrigger]); - + auto triggerInfoCopy = ini["Triggers"][m_currentTrigger]; + if (RepairTrigger(triggerInfoCopy)) { + ini.SetString("Triggers", m_currentTrigger, triggerInfoCopy); + } } -void CTriggerEventsDlg::OnSelchangeParameter() +void CTriggerEventsDlg::OnSelchangeParameter() { - CIniFile& ini=Map->GetIniFile(); + CIniFile& ini = Map->GetIniFile(); - if(m_currentTrigger.GetLength()==0) return; - int selev=m_Event.GetCurSel(); - if(selev<0) return; - int curev=m_Event.GetItemData(selev); + if (m_currentTrigger.GetLength() == 0) { + return; + } + int selev = m_Event.GetCurSel(); + if (selev < 0) { + return; + } + int curev = m_Event.GetItemData(selev); - int curselparam=m_Parameter.GetCurSel(); - if(curselparam<0) - { + int curselparam = m_Parameter.GetCurSel(); + if (curselparam < 0) { m_ParamValue.SetWindowText(""); return; } - + int curparam = m_Parameter.GetItemData(curselparam); + auto const EventData = ini["Events"][m_currentTrigger]; + int startpos = GetEventParamStart(EventData, curev);//1+curev*3; - int curparam=m_Parameter.GetItemData(curselparam); - - - CString EventData; - EventData=ini.sections["Events"].values[(LPCTSTR)m_currentTrigger]; - - int startpos=GetEventParamStart(EventData, curev);//1+curev*3; - // MW FIX FOR CODE!=0 - int original_cuparam=curparam; + int original_cuparam = curparam; #ifdef RA2_MODE - CString Param1=GetParam(g_data.sections["EventsRA2"].values[GetParam(EventData,startpos)],1); - CString Code=GetParam(g_data.sections["ParamTypes"].values[Param1],2); + CString Param1 = GetParam(g_data["EventsRA2"][GetParam(EventData, startpos)], 1); + CString Code = GetParam(g_data["ParamTypes"][Param1], 2); //MessageBox(Param1, Code); - if(atoi(Code)!=0) curparam--; + if (atoi(Code) != 0) curparam--; #endif // END FIx - CString ParamType=GetParam(g_data.sections["Events"].values[GetParam(EventData,startpos)],1+curparam); + CString ParamType = GetParam(g_data["Events"][GetParam(EventData, startpos)], 1 + curparam); #ifdef RA2_MODE - if(g_data.sections["EventsRA2"].FindName(GetParam(EventData, startpos))>=0) ParamType=GetParam(g_data.sections["EventsRA2"].values[GetParam(EventData,startpos)],1+curparam); + if (g_data["EventsRA2"].FindIndex(GetParam(EventData, startpos)) >= 0) { + ParamType = GetParam(g_data["EventsRA2"][GetParam(EventData, startpos)], 1 + curparam); + } #endif - if(atoi(ParamType)<0) - { + if (atoi(ParamType) < 0) { + return; } - else + + CString ListType = GetParam(g_data["ParamTypes"][ParamType], 1); + + HandleParamList(m_ParamValue, atoi(ListType)); + m_ParamValue.SetWindowText(GetParam(EventData, startpos + 1 + original_cuparam)); + + int i; + BOOL bFound = FALSE; + for (i = 0; i < m_ParamValue.GetCount(); i++) { - CString ListType=GetParam(g_data.sections["ParamTypes"].values[ParamType],1); - - HandleParamList(m_ParamValue, atoi(ListType)); - m_ParamValue.SetWindowText(GetParam(EventData,startpos+1+original_cuparam)); - - int i; - BOOL bFound=FALSE; - for(i=0;iGetIniFile(); + CIniFile& ini = Map->GetIniFile(); - if(m_currentTrigger.GetLength()==0) return; - int selev=m_Event.GetCurSel(); - if(selev<0) return; - int curev=m_Event.GetItemData(selev); + if (m_currentTrigger.GetLength() == 0) { + return; + } + int selev = m_Event.GetCurSel(); + if (selev < 0) { + return; + } + int curev = m_Event.GetItemData(selev); - int curselparam=m_Parameter.GetCurSel(); - if(curselparam<0) + int curselparam = m_Parameter.GetCurSel(); + if (curselparam < 0) { m_ParamValue.SetWindowText(""); return; } - int curparam=m_Parameter.GetItemData(curselparam); - - CString EventData; - EventData=ini.sections["Events"].values[(LPCTSTR)m_currentTrigger]; - - int startpos=GetEventParamStart(EventData, curev);// 1+curev*3; + int curparam = m_Parameter.GetItemData(curselparam); + + auto const& eventData = ini["Events"][m_currentTrigger]; + + int startpos = GetEventParamStart(eventData, curev);// 1+curev*3; CString newVal; @@ -496,9 +506,11 @@ void CTriggerEventsDlg::OnEditchangeParamvalue() TruncSpace(newVal); newVal.TrimLeft(); - if(newVal.Find(",",0)>=0) newVal.SetAt(newVal.Find(",",0), 0); + if (newVal.Find(",", 0) >= 0) { + newVal.SetAt(newVal.Find(",", 0), 0); + } - ini.sections["Events"].values[(LPCTSTR)m_currentTrigger]=SetParam(EventData, startpos+1+curparam, newVal); + ini.SetString("Events", m_currentTrigger, SetParam(eventData, startpos + 1 + curparam, newVal)); } void CTriggerEventsDlg::UpdateDialog() @@ -523,26 +535,23 @@ void CTriggerEventsDlg::UpdateDialog() CString sec="EventsRA2"; #endif - for(i=0;i=0) + if(g_data.sections["EventsRA2"].FindIndex(eventid)>=0) eventdata=g_data.sections["EventsRA2"].values[eventid]; #endif*/ - CString text=eventid+" "+GetParam(eventdata,0); - text.Replace("%1",","); + CString text = eventid + " " + GetParam(eventdata, 0); + text.Replace("%1", ","); #ifdef RA2_MODE // MW 07/18/01 // for yuri mode, only check if it´s for RA2, else support it only if YR isnt´needed... - if(GetParam(eventdata, 7)=="1" && ( yuri_mode || !atoi(GetParam(eventdata,9)) ) ) - { + if (GetParam(eventdata, 7) == "1" && (yuri_mode || !atoi(GetParam(eventdata, 9)))) { #else - if(GetParam(eventdata, 6)=="1") + if (GetParam(eventdata, 6) == "1") { #endif m_EventType.AddString(text); @@ -554,8 +563,8 @@ void CTriggerEventsDlg::UpdateDialog() int cur_sel=m_Event.GetCurSel(); while(m_Event.DeleteString(0)!=CB_ERR); - CString Data=ini.sections["Events"].values[m_currentTrigger]; - int count=atoi(GetParam(Data,0)); + auto const& data = ini["Events"][m_currentTrigger]; + int count = atoi(GetParam(data, 0)); for(i=0;i=count) cur_sel=count-1; + if (cur_sel < 0) { + cur_sel = 0; + } + if (cur_sel >= count) { + cur_sel = count - 1; + } m_Event.SetCurSel(cur_sel); diff --git a/MissionEditor/TriggerOptionsDlg.cpp b/MissionEditor/TriggerOptionsDlg.cpp index 45c8f85..05331ca 100644 --- a/MissionEditor/TriggerOptionsDlg.cpp +++ b/MissionEditor/TriggerOptionsDlg.cpp @@ -85,99 +85,105 @@ void CTriggerOptionsDlg::UpdateDialog() { // MW 07/20/01 - CIniFile& ini=Map->GetIniFile(); - if(m_currentTrigger.GetLength()==0) return; + CIniFile& ini = Map->GetIniFile(); + if (m_currentTrigger.IsEmpty()) { + return; + } ListHouses(m_House, FALSE, TRUE, FALSE); ListTriggers(m_AttachedTrigger); m_AttachedTrigger.InsertString(0, ""); - RepairTrigger(ini.sections["Triggers"].values[m_currentTrigger]); - - m_Name.SetWindowText(GetParam(ini.sections["Triggers"].values[m_currentTrigger],2)); - m_House.SetWindowText(TranslateHouse(GetParam(ini.sections["Triggers"].values[m_currentTrigger],0), TRUE)); - CString attachedTrigger=GetParam(ini.sections["Triggers"].values[m_currentTrigger],1); - m_AttachedTrigger.SetWindowText(attachedTrigger); - - m_Disabled.SetCheck((atoi(GetParam(ini.sections["Triggers"].values[m_currentTrigger],3)))); - m_Easy.SetCheck((atoi(GetParam(ini.sections["Triggers"].values[m_currentTrigger],4)))); - m_Medium.SetCheck((atoi(GetParam(ini.sections["Triggers"].values[m_currentTrigger],5)))); - m_Hard.SetCheck((atoi(GetParam(ini.sections["Triggers"].values[m_currentTrigger],6)))); - - int i; - for(i=0;iGetIniFile(); - - if(ini.sections["Triggers"].FindName(m_currentTrigger)<0 || m_currentTrigger.GetLength()==0) return; - + if (m_currentTrigger.GetLength() == 0) { + return; + } + + CIniFile& ini = Map->GetIniFile(); + + if (!ini["Triggers"].Exists(m_currentTrigger) || m_currentTrigger.IsEmpty()) { + return; + } + CString newName; m_Name.GetWindowText(newName); - if(newName.GetLength()==0) newName=" "; + if (newName.GetLength() == 0) { + newName = " "; + } - if(newName.Find(",",0)>=0) + if (newName.Find(",", 0) >= 0) {//newName.SetAt(newName.Find(",",0), 0); - newName=newName.Left(newName.Find(",",0)); + newName = newName.Left(newName.Find(",", 0)); - m_Name.SetWindowText(newName);} + m_Name.SetWindowText(newName); + } - - ini.sections["Triggers"].values[m_currentTrigger]=SetParam(ini.sections["Triggers"].values[m_currentTrigger], 2, newName); + + ini.SetString("Triggers", m_currentTrigger, SetParam(ini["Triggers"][m_currentTrigger], 2, newName)); int i; - int p=0; - for(i=0;iGetIniFile(); - if(ini.sections["Triggers"].FindName(m_currentTrigger)<0 || m_currentTrigger.GetLength()==0) return; + if (!ini["Triggers"].Exists(m_currentTrigger) || m_currentTrigger.IsEmpty()) { + return; + } CString newHouse; m_House.GetWindowText(newHouse); @@ -188,31 +194,37 @@ void CTriggerOptionsDlg::OnEditchangeHouse() newHouse.TrimLeft(); TruncSpace(newHouse); - if(newHouse.Find(",",0)>=0) newHouse.SetAt(newHouse.Find(",",0), 0); + if (newHouse.Find(",", 0) >= 0) { + newHouse.SetAt(newHouse.Find(",", 0), 0); + } + ini.SetString("Triggers", m_currentTrigger, SetParam(ini["Triggers"][m_currentTrigger], 0, newHouse)); - - ini.sections["Triggers"].values[m_currentTrigger]=SetParam(ini.sections["Triggers"].values[m_currentTrigger], 0, newHouse); - - RepairTrigger(ini.sections["Triggers"].values[m_currentTrigger]); - + auto triggerCopy = ini["Triggers"][m_currentTrigger]; + if (RepairTrigger(triggerCopy)) { + ini.SetString("Triggers", m_currentTrigger, triggerCopy); + } } void CTriggerOptionsDlg::OnEditchangeAttachedtrigger() { CIniFile& ini=Map->GetIniFile(); - if(ini.sections["Triggers"].FindName(m_currentTrigger)<0 || m_currentTrigger.GetLength()==0) return; + if (!ini["Triggers"].Exists(m_currentTrigger) || m_currentTrigger.IsEmpty()) { + return; + } CString newTrigger; m_AttachedTrigger.GetWindowText(newTrigger); newTrigger.TrimLeft(); TruncSpace(newTrigger); - if(newTrigger.Find(",",0)>=0) newTrigger.SetAt(newTrigger.Find(",",0), 0); + if (newTrigger.Find(",", 0) >= 0) { + newTrigger.SetAt(newTrigger.Find(",", 0), 0); + } - ini.sections["Triggers"].values[m_currentTrigger]=SetParam(ini.sections["Triggers"].values[m_currentTrigger], 1, newTrigger); + ini.SetString("Triggers", m_currentTrigger, SetParam(ini["Triggers"][m_currentTrigger], 1, newTrigger)); @@ -230,11 +242,13 @@ void CTriggerOptionsDlg::OnKillFocus(CWnd* pNewWnd) ((CTriggerEditorDlg*)(this->GetOwner()->GetOwner()))->UpdateDialog(); } -void CTriggerOptionsDlg::OnEditchangeTriggertype() +void CTriggerOptionsDlg::OnEditchangeTriggertype() { - CIniFile& ini=Map->GetIniFile(); - - if(ini.sections["Triggers"].FindName(m_currentTrigger)<0 || m_currentTrigger.GetLength()==0) return; + CIniFile& ini = Map->GetIniFile(); + + if (!ini["Triggers"].Exists(m_currentTrigger) || m_currentTrigger.IsEmpty()) { + return; + } CString newType; @@ -242,18 +256,17 @@ void CTriggerOptionsDlg::OnEditchangeTriggertype() TruncSpace(newType); int i; - for(i=0;iGetIniFile(); - - if(ini.sections["Triggers"].FindName(m_currentTrigger)<0 || m_currentTrigger.GetLength()==0) return; + CIniFile& ini = Map->GetIniFile(); - BOOL bDisabled=FALSE; - if(m_Disabled.GetCheck()==0) bDisabled=FALSE; - else - bDisabled=TRUE; - - if(bDisabled) - ini.sections["Triggers"].values[m_currentTrigger]=SetParam(ini.sections["Triggers"].values[m_currentTrigger], 3, "1"); - else - ini.sections["Triggers"].values[m_currentTrigger]=SetParam(ini.sections["Triggers"].values[m_currentTrigger], 3, "0"); + if (!ini["Triggers"].Exists(m_currentTrigger) || m_currentTrigger.IsEmpty()) { + return; + } + BOOL bDisabled = FALSE; + if (m_Disabled.GetCheck() == 0) { + bDisabled = FALSE; + } else { + bDisabled = TRUE; + } - + auto const param = bDisabled ? "1" : "0"; + ini.SetString("Triggers", m_currentTrigger, SetParam(ini["Triggers"][m_currentTrigger], 3, param)); } void CTriggerOptionsDlg::OnEasy() { CIniFile& ini=Map->GetIniFile(); - if(ini.sections["Triggers"].FindName(m_currentTrigger)<0 || m_currentTrigger.GetLength()==0) return; + if (!ini["Triggers"].Exists(m_currentTrigger) || m_currentTrigger.IsEmpty()) { + return; + } BOOL bEasy=FALSE; - if(m_Easy.GetCheck()==0) bEasy=FALSE; - else - bEasy=TRUE; - - if(bEasy) - ini.sections["Triggers"].values[m_currentTrigger]=SetParam(ini.sections["Triggers"].values[m_currentTrigger], 4, "1"); - else - ini.sections["Triggers"].values[m_currentTrigger]=SetParam(ini.sections["Triggers"].values[m_currentTrigger], 4, "0"); - + if (m_Easy.GetCheck() == 0) { + bEasy = FALSE; + } else { + bEasy = TRUE; + } + auto const param = bEasy ? "1" : "0"; + ini.SetString("Triggers", m_currentTrigger, SetParam(ini["Triggers"][m_currentTrigger], 4, param)); } void CTriggerOptionsDlg::OnMedium() { CIniFile& ini=Map->GetIniFile(); - if(ini.sections["Triggers"].FindName(m_currentTrigger)<0 || m_currentTrigger.GetLength()==0) return; + if (!ini["Triggers"].Exists(m_currentTrigger) || m_currentTrigger.IsEmpty()) { + return; + } BOOL bMedium=FALSE; - if(m_Medium.GetCheck()==0) bMedium=FALSE; - else - bMedium=TRUE; - - if(bMedium) - ini.sections["Triggers"].values[m_currentTrigger]=SetParam(ini.sections["Triggers"].values[m_currentTrigger], 5, "1"); - else - ini.sections["Triggers"].values[m_currentTrigger]=SetParam(ini.sections["Triggers"].values[m_currentTrigger], 5, "0"); + if (m_Medium.GetCheck() == 0) { + bMedium = FALSE; + } else { + bMedium = TRUE; + } + auto const param = bMedium ? "1" : "0"; + ini.SetString("Triggers", m_currentTrigger, SetParam(ini["Triggers"][m_currentTrigger], 5, param)); } void CTriggerOptionsDlg::OnHard() { CIniFile& ini=Map->GetIniFile(); - if(ini.sections["Triggers"].FindName(m_currentTrigger)<0 || m_currentTrigger.GetLength()==0) return; + if (!ini["Triggers"].Exists(m_currentTrigger) || m_currentTrigger.IsEmpty()) { + return; + } BOOL bHard=FALSE; - if(m_Hard.GetCheck()==0) bHard=FALSE; - else - bHard=TRUE; - - if(bHard) - ini.sections["Triggers"].values[m_currentTrigger]=SetParam(ini.sections["Triggers"].values[m_currentTrigger], 6, "1"); - else - ini.sections["Triggers"].values[m_currentTrigger]=SetParam(ini.sections["Triggers"].values[m_currentTrigger], 6, "0"); + if (m_Hard.GetCheck() == 0) { + bHard = FALSE; + } else { + bHard = TRUE; + } + auto const param = bHard ? "1" : "0"; + ini.SetString("Triggers", m_currentTrigger, SetParam(ini["Triggers"][m_currentTrigger], 6, param)); } //MW 07/20/01 diff --git a/MissionEditor/Triggers.cpp b/MissionEditor/Triggers.cpp index 4d8e775..bce2fd7 100644 --- a/MissionEditor/Triggers.cpp +++ b/MissionEditor/Triggers.cpp @@ -189,35 +189,23 @@ void CTriggers::UpdateDialog() int i; m_Trigger2.AddString(""); - for(i=0;iDeleteString(0)!=CB_ERR); - if(ini.sections.find("Waypoints")!=ini.sections.end()) - { - for(i=0;iAddString(*ini.sections["Waypoints"].GetValueName(i)); - } + + for (auto const& [num, coord] : ini["Waypoints"]) { + wayp->AddString(num); } - - if(sel==-1 || m_Trigger.SetCurSel(sel)==FALSE) - { + if(sel==-1 || m_Trigger.SetCurSel(sel)==FALSE) { m_Trigger.SetCurSel(0); } - if(selat==-1 || m_Trigger.SetCurSel(selat)==FALSE) - { + if(selat==-1 || m_Trigger.SetCurSel(selat)==FALSE) { m_Action.SetCurSel(0); } - if(selev==-1 || m_Trigger.SetCurSel(selev)==FALSE) - { + if(selev==-1 || m_Trigger.SetCurSel(selev)==FALSE) { m_Event.SetCurSel(0); } @@ -269,20 +250,19 @@ void CTriggers::OnSelchangeTrigger() m_Trigger.GetLBText(sel, CurrentTrigger); TruncSpace(CurrentTrigger); - TriggerData=ini.sections["Triggers"].values[CurrentTrigger]; - EventData=ini.sections["Events"].values[CurrentTrigger]; - ActionData=ini.sections["Actions"].values[CurrentTrigger]; + TriggerData = ini.GetString("Triggers", CurrentTrigger); + EventData = ini.GetString("Events", CurrentTrigger); + ActionData = ini.GetString("Actions", CurrentTrigger); m_Name=GetParam(TriggerData, 2); m_House.SetWindowText(TranslateHouse(GetParam(TriggerData,0), TRUE)); CString trig2=GetParam(TriggerData,1); - if(ini.sections["Triggers"].values.find(trig2)!=ini.sections["Triggers"].values.end()) - { - trig2+=" ("; - trig2+=GetParam( ini.sections["Triggers"].values[GetParam(TriggerData,1)],2); - trig2+=")"; + if (ini["Triggers"].Exists(trig2)) { + trig2 += " ("; + trig2 += GetParam(ini["Triggers"][GetParam(TriggerData, 1)], 2); + trig2 += ")"; } m_Trigger2.SetWindowText(trig2); @@ -338,11 +318,10 @@ void CTriggers::OnSelchangeEvent() TruncSpace(CurrentTrigger); - CString EventData; - EventData=ini.sections["Events"].values[(LPCTSTR)CurrentTrigger]; + auto const& eventData = ini["Events"][CurrentTrigger]; int startpos=1+selev*3; - CString EventType=GetParam(EventData,startpos); + CString EventType=GetParam(eventData,startpos); m_EventType.SetWindowText(EventType); for(i=0;iGetIniFile(); int sel=m_Trigger.GetCurSel(); - if(sel<0) return; + if (sel < 0) { + return; + } CString CurrentTrigger; m_Trigger.GetLBText(sel, CurrentTrigger); @@ -417,7 +397,7 @@ void CTriggers::OnEditchangeHouse() house=TranslateHouse(house); - ini.sections["Triggers"].values[(LPCTSTR)CurrentTrigger]=SetParam(ini.sections["Triggers"].values[(LPCTSTR)CurrentTrigger], 0, (LPCTSTR)house); + ini.SetString("Triggers", CurrentTrigger, SetParam(ini["Triggers"][CurrentTrigger], 0, house)); } void CTriggers::OnSelchangeHouse() @@ -442,14 +422,16 @@ void CTriggers::OnChangeName() int esel=name.GetSel(); int sel=m_Trigger.GetCurSel(); - if(sel<0) return; + if (sel < 0) { + return; + } CString CurrentTrigger; m_Trigger.GetLBText(sel, CurrentTrigger); TruncSpace(CurrentTrigger); - ini.sections["Triggers"].values[(LPCTSTR)CurrentTrigger]=SetParam(ini.sections["Triggers"].values[(LPCTSTR)CurrentTrigger], 2, (LPCTSTR)m_Name); + ini.SetString("Triggers", CurrentTrigger, SetParam(ini["Triggers"][CurrentTrigger], 2, m_Name)); UpdateDialog(); @@ -465,15 +447,16 @@ void CTriggers::OnChangeFlag1() UpdateData(); int sel=m_Trigger.GetCurSel(); - if(sel<0) return; + if (sel < 0) { + return; + } CString CurrentTrigger; m_Trigger.GetLBText(sel, CurrentTrigger); TruncSpace(CurrentTrigger); - - ini.sections["Triggers"].values[(LPCTSTR)CurrentTrigger]=SetParam(ini.sections["Triggers"].values[(LPCTSTR)CurrentTrigger], 3, (LPCTSTR)m_F1); + ini.SetString("Triggers", CurrentTrigger, SetParam(ini["Triggers"][CurrentTrigger], 3, m_F1)); } void CTriggers::OnChangeFlag2() @@ -483,14 +466,16 @@ void CTriggers::OnChangeFlag2() UpdateData(); int sel=m_Trigger.GetCurSel(); - if(sel<0) return; + if (sel < 0) { + return; + } CString CurrentTrigger; m_Trigger.GetLBText(sel, CurrentTrigger); TruncSpace(CurrentTrigger); - - ini.sections["Triggers"].values[(LPCTSTR)CurrentTrigger]=SetParam(ini.sections["Triggers"].values[(LPCTSTR)CurrentTrigger], 4, (LPCTSTR)m_F2); + + ini.SetString("Triggers", CurrentTrigger, SetParam(ini["Triggers"][CurrentTrigger], 4, m_F2)); } @@ -501,14 +486,16 @@ void CTriggers::OnChangeFlag3() UpdateData(); int sel=m_Trigger.GetCurSel(); - if(sel<0) return; + if (sel < 0) { + return; + } CString CurrentTrigger; m_Trigger.GetLBText(sel, CurrentTrigger); TruncSpace(CurrentTrigger); - ini.sections["Triggers"].values[(LPCTSTR)CurrentTrigger]=SetParam(ini.sections["Triggers"].values[(LPCTSTR)CurrentTrigger], 5, (LPCTSTR)m_F3); + ini.SetString("Triggers", CurrentTrigger, SetParam(ini["Triggers"][CurrentTrigger], 5, m_F3)); } @@ -520,14 +507,16 @@ void CTriggers::OnChangeFlag4() UpdateData(); int sel=m_Trigger.GetCurSel(); - if(sel<0) return; + if (sel < 0) { + return; + } CString CurrentTrigger; m_Trigger.GetLBText(sel, CurrentTrigger); TruncSpace(CurrentTrigger); - ini.sections["Triggers"].values[(LPCTSTR)CurrentTrigger]=SetParam(ini.sections["Triggers"].values[(LPCTSTR)CurrentTrigger], 6, (LPCTSTR)m_F4); + ini.SetString("Triggers",CurrentTrigger,SetParam(ini["Triggers"][CurrentTrigger], 6, m_F4)); } @@ -538,14 +527,16 @@ void CTriggers::OnChangeFlag5() UpdateData(); int sel=m_Trigger.GetCurSel(); - if(sel<0) return; + if (sel < 0) { + return; + } CString CurrentTrigger; m_Trigger.GetLBText(sel, CurrentTrigger); TruncSpace(CurrentTrigger); - ini.sections["Triggers"].values[(LPCTSTR)CurrentTrigger]=SetParam(ini.sections["Triggers"].values[(LPCTSTR)CurrentTrigger], 7, (LPCTSTR)m_F5); + ini.SetString("Triggers", CurrentTrigger, SetParam(ini["Triggers"][CurrentTrigger], 7, m_F5)); } @@ -554,7 +545,9 @@ void CTriggers::OnEditchangeTrigger2() CIniFile& ini=Map->GetIniFile(); int sel=m_Trigger.GetCurSel(); - if(sel<0) return; + if (sel < 0) { + return; + } CString CurrentTrigger; m_Trigger.GetLBText(sel, CurrentTrigger); @@ -564,7 +557,7 @@ void CTriggers::OnEditchangeTrigger2() m_Trigger2.GetWindowText(trg); TruncSpace(trg); - ini.sections["Triggers"].values[(LPCTSTR)CurrentTrigger]=SetParam(ini.sections["Triggers"].values[(LPCTSTR)CurrentTrigger], 1, (LPCTSTR)trg); + ini.SetString("Triggers", CurrentTrigger, SetParam(ini["Triggers"][CurrentTrigger], 1, trg)); } void CTriggers::OnSelchangeTrigger2() @@ -605,18 +598,19 @@ void CTriggers::OnEditchangeEventtype() int pos=1+3*sel2; - ini.sections["Events"].values[(LPCTSTR)CurrentTrigger]=SetParam(ini.sections["Events"].values[(LPCTSTR)CurrentTrigger], pos, (LPCTSTR)eventtype); - - if(g_data.sections["Events"].FindName(eventtype)<0) return; + ini.SetString("Events", CurrentTrigger, SetParam(ini["Events"][CurrentTrigger], pos, eventtype)); + if (g_data["Events"].FindIndex(eventtype) < 0) { + return; + } CString ptype[2]; - ptype[0]=GetParam(g_data.sections["Events"].values[eventtype],1); - ptype[1]=GetParam(g_data.sections["Events"].values[eventtype],2); + ptype[0]=GetParam(g_data["Events"][eventtype],1); + ptype[1]=GetParam(g_data["Events"][eventtype],2); int pListType[2]; - pListType[0]=atoi(GetParam(g_data.sections["ParamTypes"].values[ptype[0]], 1)); - pListType[1]=atoi(GetParam(g_data.sections["ParamTypes"].values[ptype[1]], 1)); + pListType[0]=atoi(GetParam(g_data["ParamTypes"][ptype[0]], 1)); + pListType[1]=atoi(GetParam(g_data["ParamTypes"][ptype[1]], 1)); int i; for(i=0;i<2;i++) @@ -641,7 +635,7 @@ void CTriggers::OnEditchangeEventtype() continue; } - *label=GetParam(g_data.sections["ParamTypes"].values[ptype[i]], 0); + *label=GetParam(g_data["ParamTypes"][ptype[i]], 0); @@ -701,7 +695,7 @@ void CTriggers::OnEditchangeEventparam1() int pos=1+3*sel2+1; - ini.sections["Events"].values[(LPCTSTR)CurrentTrigger]=SetParam(ini.sections["Events"].values[(LPCTSTR)CurrentTrigger], pos, (LPCTSTR)param1); + ini.SetString("Events", CurrentTrigger, SetParam(ini["Events"][CurrentTrigger], pos, param1)); } @@ -734,7 +728,7 @@ void CTriggers::OnEditchangeEventparam2() int pos=1+3*sel2+2; - ini.sections["Events"].values[(LPCTSTR)CurrentTrigger]=SetParam(ini.sections["Events"].values[(LPCTSTR)CurrentTrigger], pos, (LPCTSTR)param2); + ini.SetString("Events", CurrentTrigger, SetParam(ini["Events"][CurrentTrigger], pos, param2)); } @@ -787,27 +781,30 @@ void CTriggers::OnEditchangeActiontype() int pos=1+8*sel2; - ini.sections["Actions"].values[(LPCTSTR)CurrentTrigger]=SetParam(ini.sections["Actions"].values[(LPCTSTR)CurrentTrigger], pos, (LPCTSTR)actiontype); + ini.SetString("Actions", CurrentTrigger, SetParam(ini["Actions"][CurrentTrigger], pos, actiontype)); - if(g_data.sections["Actions"].FindName(actiontype)<0) return; + if (g_data["Actions"].FindIndex(actiontype) < 0) { + return; + } CString ptype[6]; - ptype[0]=GetParam(g_data.sections["Actions"].values[actiontype],1); - ptype[1]=GetParam(g_data.sections["Actions"].values[actiontype],2); - ptype[2]=GetParam(g_data.sections["Actions"].values[actiontype],3); - ptype[3]=GetParam(g_data.sections["Actions"].values[actiontype],4); - ptype[4]=GetParam(g_data.sections["Actions"].values[actiontype],5); - ptype[5]=GetParam(g_data.sections["Actions"].values[actiontype],6); + ptype[0]=GetParam(g_data["Actions"][actiontype],1); + ptype[1]=GetParam(g_data["Actions"][actiontype],2); + ptype[2]=GetParam(g_data["Actions"][actiontype],3); + ptype[3]=GetParam(g_data["Actions"][actiontype],4); + ptype[4]=GetParam(g_data["Actions"][actiontype],5); + ptype[5]=GetParam(g_data["Actions"][actiontype],6); - if(GetParam(g_data.sections["Actions"].values[actiontype],7)=="0") + if (GetParam(g_data["Actions"][actiontype], 7) == "0") { m_LAW="Unused"; - else - m_LAW="Waypoint:"; + } else { + m_LAW = "Waypoint:"; + } int pListType[6]; - pListType[0]=atoi(GetParam(g_data.sections["ParamTypes"].values[ptype[0]], 1)); - pListType[1]=atoi(GetParam(g_data.sections["ParamTypes"].values[ptype[1]], 1)); + pListType[0]=atoi(GetParam(g_data["ParamTypes"][ptype[0]], 1)); + pListType[1]=atoi(GetParam(g_data["ParamTypes"][ptype[1]], 1)); @@ -842,7 +839,7 @@ void CTriggers::OnEditchangeActiontype() continue; } - *label = GetParam(g_data.sections["ParamTypes"].values[ptype[i]], 0); + *label = GetParam(g_data["ParamTypes"][ptype[i]], 0); @@ -1041,7 +1038,7 @@ void CTriggers::OnEditchangeActionwaypoint() int pos=1+8*sel2+7; - ini.sections["Actions"].values[(LPCTSTR)CurrentTrigger]=SetParam(ini.sections["Actions"].values[(LPCTSTR)CurrentTrigger], pos, (LPCTSTR)waypoint); + ini.SetString("Actions", CurrentTrigger, SetParam(ini["Actions"][CurrentTrigger], pos, waypoint)); } @@ -1059,9 +1056,13 @@ void CTriggers::OnEditchangeActionparam1() CIniFile& ini=Map->GetIniFile(); int sel=m_Trigger.GetCurSel(); - if(sel<0) return; + if (sel < 0) { + return; + } int sel2=m_Action.GetCurSel(); - if(sel2<0) return; + if (sel2 < 0) { + return; + } CString CurrentTrigger; @@ -1074,7 +1075,7 @@ void CTriggers::OnEditchangeActionparam1() int pos=1+8*sel2+1; - ini.sections["Actions"].values[(LPCTSTR)CurrentTrigger]=SetParam(ini.sections["Actions"].values[(LPCTSTR)CurrentTrigger], pos, (LPCTSTR)p1); + ini.SetString("Actions", CurrentTrigger, SetParam(ini["Actions"][CurrentTrigger], pos, p1)); } @@ -1107,7 +1108,7 @@ void CTriggers::OnEditchangeActionparam2() int pos=1+8*sel2+2; - ini.sections["Actions"].values[(LPCTSTR)CurrentTrigger]=SetParam(ini.sections["Actions"].values[(LPCTSTR)CurrentTrigger], pos, (LPCTSTR)p2); + ini.SetString("Actions", CurrentTrigger, SetParam(ini["Actions"][CurrentTrigger], pos, p2)); } @@ -1140,7 +1141,7 @@ void CTriggers::OnEditchangeActionparam3() int pos=1+8*sel2+3; - ini.sections["Actions"].values[(LPCTSTR)CurrentTrigger]=SetParam(ini.sections["Actions"].values[(LPCTSTR)CurrentTrigger], pos, (LPCTSTR)p3); + ini.SetString("Actions", CurrentTrigger, SetParam(ini["Actions"][CurrentTrigger], pos, p3)); } @@ -1173,7 +1174,7 @@ void CTriggers::OnEditchangeActionparam4() int pos=1+8*sel2+4; - ini.sections["Actions"].values[(LPCTSTR)CurrentTrigger]=SetParam(ini.sections["Actions"].values[(LPCTSTR)CurrentTrigger], pos, (LPCTSTR)p4); + ini.SetString("Actions", CurrentTrigger, SetParam(ini["Actions"][CurrentTrigger], pos, p4)); } @@ -1206,7 +1207,7 @@ void CTriggers::OnEditchangeActionparam5() int pos=1+8*sel2+5; - ini.sections["Actions"].values[(LPCTSTR)CurrentTrigger]=SetParam(ini.sections["Actions"].values[(LPCTSTR)CurrentTrigger], pos, (LPCTSTR)p5); + ini.SetString("Actions", CurrentTrigger, SetParam(ini["Actions"][CurrentTrigger], pos, p5)); } @@ -1239,7 +1240,7 @@ void CTriggers::OnEditchangeActionparam6() int pos=1+8*sel2+6; - ini.sections["Actions"].values[(LPCTSTR)CurrentTrigger]=SetParam(ini.sections["Actions"].values[(LPCTSTR)CurrentTrigger], pos, (LPCTSTR)p6); + ini.SetString("Actions", CurrentTrigger, SetParam(ini["Actions"][CurrentTrigger], pos, p6)); } @@ -1264,16 +1265,14 @@ void CTriggers::OnAddevent() m_Trigger.GetLBText(sel, CurrentTrigger); TruncSpace(CurrentTrigger); - CIniFileSection& sec=ini.sections["Events"]; + CIniFileSection& sec=ini.AddSection("Events"); - int cval=atoi(GetParam(sec.values[(LPCTSTR)CurrentTrigger],0)); + int cval=atoi(GetParam(sec[CurrentTrigger],0)); cval++; char c[50]; itoa(cval,c,10); - sec.values[(LPCTSTR)CurrentTrigger]=SetParam(sec.values[(LPCTSTR)CurrentTrigger],0,c); - sec.values[(LPCTSTR)CurrentTrigger]+=",13,0,0"; - + sec.SetString(CurrentTrigger, SetParam(sec[CurrentTrigger], 0, c) + ",13,0,0"); UpdateDialog(); @@ -1284,49 +1283,53 @@ void CTriggers::OnAddevent() } -void CTriggers::OnDeleteevent() +void CTriggers::OnDeleteevent() { - CIniFile& ini=Map->GetIniFile(); + CIniFile& ini = Map->GetIniFile(); - int sel=m_Trigger.GetCurSel(); - if(sel<0) return; - int sel2=m_Event.GetCurSel(); - if(sel2<0) return; - if(MessageBox("Do you really want to delete this event?","Delete event", MB_YESNO)==IDNO) return; + int sel = m_Trigger.GetCurSel(); + if (sel < 0) { + return; + } + int sel2 = m_Event.GetCurSel(); + if (sel2 < 0) { + return; + } + if (MessageBox("Do you really want to delete this event?", "Delete event", MB_YESNO) == IDNO) { + return; + } CString CurrentTrigger; m_Trigger.GetLBText(sel, CurrentTrigger); TruncSpace(CurrentTrigger); - CIniFileSection& sec=ini.sections["Events"]; + auto const& sec = ini["Events"]; - CString data; - data=sec.values[(LPCTSTR)CurrentTrigger]; + auto data = sec[CurrentTrigger]; - int v=atoi(GetParam(data,0)); + int v = atoi(GetParam(data, 0)); char c[50]; v--; - itoa(v,c,10); - data=SetParam(data,0, c); + itoa(v, c, 10); + data = SetParam(data, 0, c); - int pos=1+sel2*3; - int posc=1+v*3; - int i; - for(i=0;i<3;i++) - data=SetParam(data,pos+i, GetParam(data,posc+i)); + int pos = 1 + sel2 * 3; + int posc = 1 + v * 3; - char* cupos=(char*)(LPCTSTR)data; - for(i=0;iGetIniFile(); int sel=m_Trigger.GetCurSel(); - if(sel<0) return; + if (sel < 0) { + return; + } CString CurrentTrigger; m_Trigger.GetLBText(sel, CurrentTrigger); TruncSpace(CurrentTrigger); - CIniFileSection& sec=ini.sections["Actions"]; + CIniFileSection& sec=ini.AddSection("Actions"); - int cval=atoi(GetParam(sec.values[(LPCTSTR)CurrentTrigger],0)); + int cval=atoi(GetParam(sec[CurrentTrigger],0)); cval++; char c[50]; itoa(cval,c,10); - sec.values[(LPCTSTR)CurrentTrigger]=SetParam(sec.values[(LPCTSTR)CurrentTrigger],0,c); - sec.values[(LPCTSTR)CurrentTrigger]+=",0,0,0,0,0,0,0,A"; - + sec.SetString(CurrentTrigger, SetParam(sec[CurrentTrigger], 0, c) + ",0,0,0,0,0,0,0,A"); UpdateDialog(); @@ -1371,16 +1374,17 @@ void CTriggers::OnDeleteaction() if(sel<0) return; int sel2=m_Action.GetCurSel(); if(sel2<0) return; - if(MessageBox("Do you really want to delete this action?","Delete action", MB_YESNO)==IDNO) return; + if (MessageBox("Do you really want to delete this action?", "Delete action", MB_YESNO) == IDNO) { + return; + } CString CurrentTrigger; m_Trigger.GetLBText(sel, CurrentTrigger); TruncSpace(CurrentTrigger); - CIniFileSection& sec=ini.sections["Actions"]; + auto const& sec = ini["Actions"]; - CString data; - data=sec.values[(LPCTSTR)CurrentTrigger]; + auto data = sec[CurrentTrigger]; int v=atoi(GetParam(data,0)); char c[50]; @@ -1394,18 +1398,16 @@ void CTriggers::OnDeleteaction() for(i=0;i<3;i++) data=SetParam(data,pos+i, GetParam(data,posc+i)); - char* cupos=(char*)(LPCTSTR)data; - for(i=0;iGetIniFile(); int sel=m_Trigger.GetCurSel(); - if(sel<0) return; + if (sel < 0) { + return; + } - if(MessageBox("Do you really want to delete this trigger? Don´t forget to delete the attached tag (important!)","Delete trigger", MB_YESNO)==IDNO) return; + if (MessageBox("Do you really want to delete this trigger? Don´t forget to delete the attached tag (important!)", "Delete trigger", MB_YESNO) == IDNO) { + return; + } CString CurrentTrigger; m_Trigger.GetLBText(sel, CurrentTrigger); TruncSpace(CurrentTrigger); - ini.sections["Triggers"].values.erase((LPCTSTR)CurrentTrigger); - ini.sections["Events"].values.erase((LPCTSTR)CurrentTrigger); - ini.sections["Actions"].values.erase((LPCTSTR)CurrentTrigger); + ini.RemoveValueByKey( "Triggers",CurrentTrigger); + ini.RemoveValueByKey( "Events",CurrentTrigger); + ini.RemoveValueByKey( "Actions",CurrentTrigger); //UpdateDialog(); ((CFinalSunDlg*)theApp.m_pMainWnd)->UpdateDialogs(TRUE); } -void CTriggers::OnAddtrigger() +void CTriggers::OnAddtrigger() { - CIniFile& ini=Map->GetIniFile(); + CIniFile& ini = Map->GetIniFile(); - CString ID_T=GetFreeID(); - ini.sections["Triggers"].values[ID_T]="GDI,,New trigger,0,1,1,1,0"; - ini.sections["Events"].values[ID_T]="0"; - ini.sections["Actions"].values[ID_T]="0"; + CString newId = GetFreeID(); + ini.SetString("Triggers", newId, "GDI,,New trigger,0,1,1,1,0"); + ini.SetString("Events", newId, "0"); + ini.SetString("Actions", newId, "0"); - if(MessageBox("Trigger created. If you want to create a simple tag now, press Yes. The tag will be called ""New tag"", you should name it like the trigger (after you have set up the trigger).","Trigger created",MB_YESNO)) - { - CString ID_TAG=GetFreeID(); - ini.sections["Tags"].values[ID_TAG]="0,New tag,"; - ini.sections["Tags"].values[ID_TAG]+=ID_T; + if (MessageBox("Trigger created. If you want to create a simple tag now, press Yes. The tag will be called ""New tag"", you should name it like the trigger (after you have set up the trigger).", "Trigger created", MB_YESNO)) { + CString newTagId = GetFreeID(); + ini.SetString("Tags", newTagId, "0,New tag," + newId); } //UpdateDialog(); ((CFinalSunDlg*)theApp.m_pMainWnd)->UpdateDialogs(TRUE); - + } diff --git a/MissionEditor/Unit.cpp b/MissionEditor/Unit.cpp index 42b716b..718b202 100644 --- a/MissionEditor/Unit.cpp +++ b/MissionEditor/Unit.cpp @@ -88,15 +88,15 @@ void CUnit::Init(CString house, CString strength, CString direction, CString act { CIniFile& ini=Map->GetIniFile(); - if(house=="") - { - m_house=*rules.sections["Houses"].GetValue(0); - if(ini.sections.find("Houses")!=ini.sections.end()) - if(ini.sections["Houses"].values.size()>0) - m_house=TranslateHouse(*ini.sections["Houses"].GetValue(0), TRUE); + if (house.IsEmpty()) { + auto const& houseSec = rules["Houses"]; + m_house = houseSec.Nth(0).second; + if (houseSec.Size() > 0) { + m_house = TranslateHouse(m_house, TRUE); + } + } else { + m_house = TranslateHouse(house, TRUE); } - else - m_house=TranslateHouse(house, TRUE); m_flag1=flag1; m_flag2=flag2; diff --git a/MissionEditor/UserScriptsDlg.cpp b/MissionEditor/UserScriptsDlg.cpp index a932135..8e602ba 100644 --- a/MissionEditor/UserScriptsDlg.cpp +++ b/MissionEditor/UserScriptsDlg.cpp @@ -1148,21 +1148,21 @@ void CUserScriptsDlg::OnOK() variables[params[0]]=ID_T; } - ini.sections["Triggers"].values[ID_T]=params[1]; - ini.sections["Events"].values[ID_T]=params[2]; - ini.sections["Actions"].values[ID_T]=params[3]; + ini.SetString("Triggers", ID_T, params[1]); + ini.SetString("Events", ID_T, params[2]); + ini.SetString("Actions", ID_T, params[3]); BOOL tag=TRUE; params[4].MakeLower(); if(params[4]=="false" || params[4]=="no") tag=FALSE; - if(tag) - { - CString ID_TAG=GetFreeID(); - ini.sections["Tags"].values[ID_TAG]="0,"; - ini.sections["Tags"].values[ID_TAG]+=GetParam(params[1],2); - ini.sections["Tags"].values[ID_TAG]+=","; - ini.sections["Tags"].values[ID_TAG]+=ID_T; + if(tag) { + auto const ID_TAG=GetFreeID(); + CString def = "0,"; + def += GetParam(params[1], 2);; + def += ","; + def += ID_T; + ini.SetString("Tags", ID_TAG, def); } report+="Trigger " + GetParam(params[1],2) + " added\r\n"; @@ -1187,12 +1187,12 @@ void CUserScriptsDlg::OnOK() } } - //if(ini.sections[params[0]].FindName(params[1])>=0) + //if(ini.sections[params[0]].FindIndex(params[1])>=0) { if(bSafeMode) goto nextline; } - ini.sections[params[0]].values[params[1]]=params[2]; + ini.SetString(params[0], params[1], params[2]); report +=params[0]+(CString)"->"+params[1]+(CString) " set to \"" + params[2] + "\"\r\n"; @@ -1217,12 +1217,11 @@ void CUserScriptsDlg::OnOK() } } - if(ini.sections.find(params[1])==ini.sections.end() || ini.sections[params[1]].FindName(params[2])<0) - { - variables[params[0]]=""; + if (ini[params[1]].FindIndex(params[2]) < 0) { + variables[params[0]] = ""; + } else { + variables[params[0]] = ini.GetString(params[1], params[2]); } - else - variables[params[0]]=ini.sections[params[1]].values[params[2]]; } else if(name==ID_SET_SAFE_MODE) { @@ -1667,7 +1666,7 @@ void CUserScriptsDlg::OnOK() if(bSafeMode && n>=0) { - if(ini.sections["Waypoints"].FindName(id)>=0) + if(ini["Waypoints"].FindIndex(id)>=0) { goto nextline; } @@ -1753,7 +1752,7 @@ void CUserScriptsDlg::OnOK() variables[params[0]]=ID_T; } - ini.sections["AITriggerTypes"].values[ID_T]=params[1]; + ini.SetString("AITriggerTypes", ID_T, params[1]); report+="AI Trigger " + GetParam(params[1],0) + " added\r\n"; @@ -1787,7 +1786,7 @@ void CUserScriptsDlg::OnOK() } CString ID_TAG=ID_T; //GetFreeID(); - ini.sections["Tags"].values[ID_TAG]=params[1]; + ini.SetString("Tags", ID_TAG, params[1]); report+="Tag " + GetParam(params[1],1) + " added\r\n"; @@ -2649,7 +2648,7 @@ void CUserScriptsDlg::OnOK() goto nextline; } - lastStructureDeleted=*ini.sections["Structures"].GetValueName(index); + lastStructureDeleted = ini["Structures"].Nth(index).first; Map->DeleteStructure(index); report+="Structure deleted\r\n"; @@ -2684,7 +2683,7 @@ void CUserScriptsDlg::OnOK() goto nextline; } - lastUnitDeleted=*ini.sections["Units"].GetValueName(index); + lastUnitDeleted = ini["Units"].Nth(index).first; Map->DeleteUnit(index); report+="Vehicle deleted\r\n"; @@ -2720,7 +2719,7 @@ void CUserScriptsDlg::OnOK() goto nextline; } - lastAircraftDeleted=*ini.sections["Aircraft"].GetValueName(index); + lastAircraftDeleted = ini["Aircraft"].Nth(index).first; Map->DeleteAircraft(index); report+="Aircraft deleted\r\n"; @@ -3099,9 +3098,8 @@ void CUserScriptsDlg::OnOK() int index=atoi(params[1]); CString s; - if(index>=0 && indexGetAircraftCount()) - { - s=*ini.sections["Aircraft"].GetValue(index); + if (index >= 0 && index < Map->GetAircraftCount()) { + s = ini["Aircraft"].Nth(index).second; } variables[params[0]]=s; @@ -3126,9 +3124,8 @@ void CUserScriptsDlg::OnOK() int index=atoi(params[1]); CString s; - if(index>=0 && indexGetStructureCount()) - { - s=*ini.sections["Structures"].GetValue(index); + if (index >= 0 && index < Map->GetStructureCount()) { + s = ini["Structures"].Nth(index).second; } variables[params[0]]=s; @@ -3153,9 +3150,8 @@ void CUserScriptsDlg::OnOK() int index=atoi(params[1]); CString s; - if(index>=0 && indexGetUnitCount()) - { - s=*ini.sections["Units"].GetValue(index); + if (index >= 0 && index < Map->GetUnitCount()) { + s = ini["Units"].Nth(index).second; } variables[params[0]]=s; diff --git a/MissionEditor/ViewObjects.cpp b/MissionEditor/ViewObjects.cpp index 28a0782..06c4312 100644 --- a/MissionEditor/ViewObjects.cpp +++ b/MissionEditor/ViewObjects.cpp @@ -258,9 +258,14 @@ void CViewObjects::OnSelchanged(NMHDR* pNMHDR, LRESULT* pResult) case 62: int i; - if(!tiledata_count) break; - for(i=0;i<(*tiledata_count);i++) - if((*tiledata)[i].wTileSet==atoi((*tiles).sections["General"].values["SandTile"])) break; + if (!tiledata_count) { + break; + } + for (i = 0; i < (*tiledata_count); i++) { + if ((*tiledata)[i].wTileSet == tiles->GetInteger("General", "SandTile")) { + break; + } + } AD.type=i; AD.mode=ACTIONMODE_SETTILE; AD.data=0; @@ -268,9 +273,14 @@ void CViewObjects::OnSelchanged(NMHDR* pNMHDR, LRESULT* pResult) HandleBrushSize(i); break; case 63: - if(!tiledata_count) break; - for(i=0;i<(*tiledata_count);i++) - if((*tiledata)[i].wTileSet==atoi((*tiles).sections["General"].values["RoughTile"])) break; + if (!tiledata_count) { + break; + } + for (i = 0; i < (*tiledata_count); i++) { + if ((*tiledata)[i].wTileSet == tiles->GetInteger("General", "RoughTile")) { + break; + } + } AD.type=i; AD.mode=ACTIONMODE_SETTILE; AD.data=0; @@ -298,9 +308,14 @@ void CViewObjects::OnSelchanged(NMHDR* pNMHDR, LRESULT* pResult) AD.z_data=0; break; case 65: - if(!tiledata_count) break; - for(i=0;i<(*tiledata_count);i++) - if((*tiledata)[i].wTileSet==atoi((*tiles).sections["General"].values["GreenTile"])) break; + if (!tiledata_count) { + break; + } + for (i = 0; i < (*tiledata_count); i++) { + if ((*tiledata)[i].wTileSet == tiles->GetInteger("General", "GreenTile")) { + break; + } + } AD.type=i; AD.mode=ACTIONMODE_SETTILE; AD.data=0; @@ -308,9 +323,14 @@ void CViewObjects::OnSelchanged(NMHDR* pNMHDR, LRESULT* pResult) HandleBrushSize(i); break; case 66: - if(!tiledata_count) break; - for(i=0;i<(*tiledata_count);i++) - if((*tiledata)[i].wTileSet==atoi((*tiles).sections["General"].values["PaveTile"])) break; + if (!tiledata_count) { + break; + } + for (i = 0; i < (*tiledata_count); i++) { + if ((*tiledata)[i].wTileSet == tiles->GetInteger("General", "PaveTile")) { + break; + } + } AD.type=i; AD.mode=ACTIONMODE_SETTILE; AD.data=0; @@ -318,9 +338,14 @@ void CViewObjects::OnSelchanged(NMHDR* pNMHDR, LRESULT* pResult) HandleBrushSize(i); break; case 67: - if(!tiledata_count) break; - for(i=0;i<(*tiledata_count);i++) - if((*tiledata)[i].wTileSet==atoi(g_data.sections["NewUrbanInfo"].values["Morphable2"])) break; + if (!tiledata_count) { + break; + } + for (i = 0; i < (*tiledata_count); i++) { + if ((*tiledata)[i].wTileSet == g_data.GetInteger("NewUrbanInfo", "Morphable2")) { + break; + } + } AD.type=i; AD.mode=ACTIONMODE_SETTILE; AD.data=0; @@ -340,68 +365,49 @@ void CViewObjects::OnSelchanged(NMHDR* pNMHDR, LRESULT* pResult) AD.type=pos; AD.data=subpos; - if(pos==1) + if (pos == 1) { - CString sec="InfantryTypes"; - - if(subpos=30) {AD.data=30;AD.data2=subpos%1000;} + if (AD.data >= 30) { + AD.data = 30; + AD.data2 = subpos % 1000; + } } } else if(pos==7) { // set owner - //if(ini.sections.find(MAPHOUSES)!=ini.sections.end() && ini.sections[MAPHOUSES].values.size()>0) - if(ini.sections.find(MAPHOUSES)!=ini.sections.end() && ini.sections[MAPHOUSES].values.size()>0) - { - AD.data_s=*ini.sections[MAPHOUSES].GetValue(subpos); - } - else - { - AD.data_s=*rules.sections[HOUSES].GetValue(subpos); + //if(ini.find(MAPHOUSES)!=ini.end() && ini[MAPHOUSES].Size()>0) + if (ini[MAPHOUSES].Size() > 0) { + AD.data_s = ini[MAPHOUSES].Nth(subpos).second; + } else { + AD.data_s = rules[HOUSES].Nth(subpos).second; } currentOwner=AD.data_s; @@ -476,15 +478,11 @@ void CViewObjects::OnSelchanged(NMHDR* pNMHDR, LRESULT* pResult) CString sec="SmudgeTypes"; - if(subpos>; +vecSideNodeInfo collectSides() +{ + vecSideNodeInfo ret; + + auto toType = [](const CString& str) -> TechnoTypeMask { + return TechnoTypeMask(atoi(str)); + }; + + CString typeStr; + for (auto& [seq, def] : g_data["Sides"]) { + auto const commaPos = def.Find(','); + //now parse real type + if (commaPos >= 0) { + typeStr = def.Mid(commaPos + 1); + ret.push_back({ def.Mid(0, commaPos), toType(typeStr) }); + } + } + + return ret; +} + void CViewObjects::UpdateDialog() { OutputDebugString("Objectbrowser redrawn\n"); @@ -570,9 +590,9 @@ void CViewObjects::UpdateDialog() int i=0; //TV_InsertItemW(tree.m_hWnd, L"HELLO", 5, TVI_LAST, TVI_ROOT, -2); - + auto const translatedNoObj = GetLanguageStringACP("NothingObList"); HTREEITEM first=tree.InsertItem(TVIF_PARAM | TVIF_TEXT, - TranslateStringACP(GetLanguageStringACP("NothingObList")), i, i, 0, 0, -2, TVI_ROOT, TVI_LAST); + translatedNoObj, i, i, 0, 0, -2, TVI_ROOT, TVI_LAST); HTREEITEM rootitems[15]; @@ -580,7 +600,7 @@ void CViewObjects::UpdateDialog() if(!Map->IsMultiplayer() || !theApp.m_Options.bEasy) rootitems[11]=tree.InsertItem(TVIF_PARAM | TVIF_TEXT, - TranslateStringACP(sTreeRoots[11]), i, i, 0, 0, i, TVI_ROOT, TVI_LAST); + sTreeRoots[11], i, i, 0, 0, i, TVI_ROOT, TVI_LAST); for(i=0;i<10;i++) @@ -593,25 +613,28 @@ void CViewObjects::UpdateDialog() } // no tunnels in ra2 mode - if(editor_mode==ra2_mode && i==9 && !isTrue(g_data.sections["Debug"].values["AllowTunnels"])) bAllow=FALSE; + if (editor_mode == ra2_mode && i == 9 && !g_data.GetBool("Debug","AllowTunnels")) { + bAllow = FALSE; + } - if(bAllow) - rootitems[i]=tree.InsertItem(TVIF_PARAM | TVIF_TEXT, - sTreeRoots[i], i, i, 0, 0, i, TVI_ROOT, TVI_LAST); + if (bAllow) { + rootitems[i] = tree.InsertItem(TVIF_PARAM | TVIF_TEXT, + sTreeRoots[i], i, i, 0, 0, i, TVI_ROOT, TVI_LAST); + } } - rootitems[13]=tree.InsertItem(TVIF_PARAM | TVIF_TEXT, TranslateStringACP(sTreeRoots[13]), 13, 13, 0, 0, 13, TVI_ROOT, first); + rootitems[13]=tree.InsertItem(TVIF_PARAM | TVIF_TEXT, sTreeRoots[13], 13, 13, 0, 0, 13, TVI_ROOT, first); rootitems[12]=tree.InsertItem(TVIF_PARAM | TVIF_TEXT, - TranslateStringACP(sTreeRoots[12]), 12,12, 0, 0, 12, TVI_ROOT, TVI_LAST); + sTreeRoots[12], 12,12, 0, 0, 12, TVI_ROOT, TVI_LAST); rootitems[10]=tree.InsertItem(TVIF_PARAM | TVIF_TEXT, - TranslateStringACP(sTreeRoots[10]), 10, 10, 0, 0, 10, TVI_ROOT, TVI_LAST); + sTreeRoots[10], 10, 10, 0, 0, 10, TVI_ROOT, TVI_LAST); #ifdef SMUDGE_SUPP rootitems[14]=tree.InsertItem(TVIF_PARAM | TVIF_TEXT, - TranslateStringACP(sTreeRoots[14]), 14, 14, 0, 0, 10, TVI_ROOT, rootitems[4]); + sTreeRoots[14], 14, 14, 0, 0, 10, TVI_ROOT, rootitems[4]); #endif @@ -656,7 +679,7 @@ void CViewObjects::UpdateDialog() int e; int max=8; - //if(ini.sections.find(HOUSES)!=ini.sections.end() && ini.sections.find(MAPHOUSES)!=ini.sections.end()) + //if(ini.find(HOUSES)!=ini.end() && ini.find(MAPHOUSES)!=ini.end()) if(!Map->IsMultiplayer()) max=1; else @@ -764,11 +787,11 @@ void CViewObjects::UpdateDialog() } #ifndef RA2_MODE - if (!theApp.m_Options.bEasy && isTrue(g_data.sections["Debug"].values["AllowTunnels"])) + if (!theApp.m_Options.bEasy && isTrue(g_data["Debug"]["AllowTunnels"])) { tree.InsertItem(TVIF_PARAM | TVIF_TEXT, GetLanguageStringACP("NewTunnelObList"), 0, 0, 0, 0, 50, rootitems[9], TVI_LAST); tree.InsertItem(TVIF_PARAM | TVIF_TEXT, GetLanguageStringACP("ModifyTunnelObList"), 0, 0, 0, 0, 51, rootitems[9], TVI_LAST); - if (isTrue(g_data.sections["Debug"].values["AllowUnidirectionalTunnels"])) + if (isTrue(g_data["Debug"]["AllowUnidirectionalTunnels"])) { tree.InsertItem(TVIF_PARAM | TVIF_TEXT, GetLanguageStringACP("NewTunnelSingleObList"), 0, 0, 0, 0, 52, rootitems[9], TVI_LAST); tree.InsertItem(TVIF_PARAM | TVIF_TEXT, GetLanguageStringACP("ModifyTunnelSingleObList"), 0, 0, 0, 0, 53, rootitems[9], TVI_LAST); @@ -776,12 +799,10 @@ void CViewObjects::UpdateDialog() tree.InsertItem(TVIF_PARAM | TVIF_TEXT, GetLanguageStringACP("DelTunnelObList"), 0, 0, 0, 0, 54, rootitems[9], TVI_LAST); } #else - if (!theApp.m_Options.bEasy && isTrue(g_data.sections["Debug"].values["AllowTunnels"])) - { + if (!theApp.m_Options.bEasy && g_data.GetBool( "Debug","AllowTunnels")) { tree.InsertItem(TVIF_PARAM | TVIF_TEXT, GetLanguageStringACP("NewTunnelObList"), 0, 0, 0, 0, 50, rootitems[9], TVI_LAST); tree.InsertItem(TVIF_PARAM | TVIF_TEXT, GetLanguageStringACP("ModifyTunnelObList"), 0, 0, 0, 0, 51, rootitems[9], TVI_LAST); - if (isTrue(g_data.sections["Debug"].values["AllowUnidirectionalTunnels"])) - { + if (g_data.GetBool("Debug", "AllowUnidirectionalTunnels")) { tree.InsertItem(TVIF_PARAM | TVIF_TEXT, GetLanguageStringACP("NewTunnelSingleObList"), 0, 0, 0, 0, 52, rootitems[9], TVI_LAST); tree.InsertItem(TVIF_PARAM | TVIF_TEXT, GetLanguageStringACP("ModifyTunnelSingleObList"), 0, 0, 0, 0, 53, rootitems[9], TVI_LAST); } @@ -789,50 +810,46 @@ void CViewObjects::UpdateDialog() } #endif - - int lv=1; - if(!theApp.m_Options.bEasy || !Map->IsMultiplayer()) { - if(ini.sections.find(MAPHOUSES)!=ini.sections.end() && ini.sections[MAPHOUSES].values.size()>0) - { - for(i=0;i0) { + for(i=0;i0) + if(ini[MAPHOUSES].Size()>0) { - if(ini.sections[MAPHOUSES].FindValue("Neutral")>=0) + if(ini[MAPHOUSES].FindValue("Neutral")>=0) currentOwner="Neutral"; else - currentOwner=*ini.sections[MAPHOUSES].GetValue(0); + currentOwner=ini[MAPHOUSES].Nth(0).second; } else currentOwner="Neutral"; @@ -844,7 +861,7 @@ void CViewObjects::UpdateDialog() { if(overlay_visible[i] && (!yr_only[i] || yuri_mode)) { - if(!overlay_trdebug[i] || isTrue(g_data.sections["Debug"].values["EnableTrackLogic"])) + if(!overlay_trdebug[i] || g_data.GetBool("Debug", "EnableTrackLogic")) tree.InsertItem(TVIF_PARAM | TVIF_TEXT, TranslateStringACP(overlay_name[i]), 0,0,0,0, valadded*6+3000+overlay_number[i], alloverlay, TVI_LAST ); } } @@ -852,28 +869,29 @@ void CViewObjects::UpdateDialog() e=0; if(!theApp.m_Options.bEasy) { - for(i=0;i=0) id = id.Left(id.Find(' ')); - if(id.GetLength()>0) - { + if (id.Find(' ') >= 0) { + id = id.Left(id.Find(' ')); + } + if (id.GetLength() > 0) { - CString unitname=*rules.sections["OverlayTypes"].GetValue(i); #ifdef RA2_MODE - if (Map->GetTheater()==THEATER0 && g_data.sections["IgnoreTemperateRA2"].FindValue(unitname) >= 0) continue; - if (Map->GetTheater()==THEATER1 && g_data.sections["IgnoreSnowRA2"].FindValue(unitname) >= 0) continue; - if (Map->GetTheater()==THEATER2 && g_data.sections["IgnoreUrbanRA2"].FindValue(unitname) >= 0) continue; - if (Map->GetTheater()==THEATER3 && g_data.sections["IgnoreNewUrbanRA2"].FindValue(unitname) >= 0) continue; - if (Map->GetTheater()==THEATER4 && g_data.sections["IgnoreLunarRA2"].FindValue(unitname) >= 0) continue; - if (Map->GetTheater()==THEATER5 && g_data.sections["IgnoreDesertRA2"].FindValue(unitname) >= 0) continue; + if (Map->GetTheater()==THEATER0 && g_data["IgnoreTemperateRA2"].FindValue(unitname) >= 0) continue; + if (Map->GetTheater()==THEATER1 && g_data["IgnoreSnowRA2"].FindValue(unitname) >= 0) continue; + if (Map->GetTheater()==THEATER2 && g_data["IgnoreUrbanRA2"].FindValue(unitname) >= 0) continue; + if (Map->GetTheater()==THEATER3 && g_data["IgnoreNewUrbanRA2"].FindValue(unitname) >= 0) continue; + if (Map->GetTheater()==THEATER4 && g_data["IgnoreLunarRA2"].FindValue(unitname) >= 0) continue; + if (Map->GetTheater()==THEATER5 && g_data["IgnoreDesertRA2"].FindValue(unitname) >= 0) continue; #else - if (Map->GetTheater()==THEATER0 && g_data.sections["IgnoreTemperateTS"].FindValue(unitname) >= 0) continue; - if (Map->GetTheater()==THEATER1 && g_data.sections["IgnoreSnowTS"].FindValue(unitname) >= 0) continue; + if (Map->GetTheater()==THEATER0 && g_data["IgnoreTemperateTS"].FindValue(unitname) >= 0) continue; + if (Map->GetTheater()==THEATER1 && g_data["IgnoreSnowTS"].FindValue(unitname) >= 0) continue; #endif #ifdef RA2_MODE @@ -881,8 +899,7 @@ void CViewObjects::UpdateDialog() || (i>=122 && i<=125) || i==1 || (i>=0x03 && i<=0x17) || (i>=0x3d && i<=0x43) || (i>=0x4a && i<=0x65) || (i>=0xcd && i<=0xec)) { - if(!isTrue(g_data.sections["Debug"].values["DisplayAllOverlay"])) - { + if(!g_data.GetBool("Debug", "DisplayAllOverlay")) { e++; continue; } @@ -891,7 +908,7 @@ void CViewObjects::UpdateDialog() #endif - CString val=*rules.sections["OverlayTypes"].GetValue(i); + CString val = unitname; #ifdef RA2_MODE val.Replace("TIB", "ORE"); #endif @@ -903,28 +920,30 @@ void CViewObjects::UpdateDialog() } - for(i=0;iGetTheater()==THEATER0 && g_data.sections["IgnoreTemperateRA2"].FindValue(unitname) >= 0) continue; - if (Map->GetTheater()==THEATER1 && g_data.sections["IgnoreSnowRA2"].FindValue(unitname) >= 0) continue; - if (Map->GetTheater()==THEATER2 && g_data.sections["IgnoreUrbanRA2"].FindValue(unitname) >= 0) continue; - if (Map->GetTheater()==THEATER3 && g_data.sections["IgnoreNewUrbanRA2"].FindValue(unitname) >= 0) continue; - if (Map->GetTheater()==THEATER4 && g_data.sections["IgnoreLunarRA2"].FindValue(unitname) >= 0) continue; - if (Map->GetTheater()==THEATER5 && g_data.sections["IgnoreDesertRA2"].FindValue(unitname) >= 0) continue; + if (Map->GetTheater()==THEATER0 && g_data["IgnoreTemperateRA2"].FindValue(unitname) >= 0) continue; + if (Map->GetTheater()==THEATER1 && g_data["IgnoreSnowRA2"].FindValue(unitname) >= 0) continue; + if (Map->GetTheater()==THEATER2 && g_data["IgnoreUrbanRA2"].FindValue(unitname) >= 0) continue; + if (Map->GetTheater()==THEATER3 && g_data["IgnoreNewUrbanRA2"].FindValue(unitname) >= 0) continue; + if (Map->GetTheater()==THEATER4 && g_data["IgnoreLunarRA2"].FindValue(unitname) >= 0) continue; + if (Map->GetTheater()==THEATER5 && g_data["IgnoreDesertRA2"].FindValue(unitname) >= 0) continue; #else - if (Map->GetTheater()==THEATER0 && g_data.sections["IgnoreTemperateTS"].FindValue(unitname) >= 0) continue; - if (Map->GetTheater()==THEATER1 && g_data.sections["IgnoreSnowTS"].FindValue(unitname) >= 0) continue; + if (Map->GetTheater()==THEATER0 && g_data["IgnoreTemperateTS"].FindValue(unitname) >= 0) continue; + if (Map->GetTheater()==THEATER1 && g_data["IgnoreSnowTS"].FindValue(unitname) >= 0) continue; #endif #ifdef RA2_MODE - if(g_data.sections["IgnoreRA2"].FindValue(unitname)>=0) continue; + if(g_data["IgnoreRA2"].FindValue(unitname)>=0) continue; #else - if(g_data.sections["IgnoreTS"].FindValue(unitname) >= 0) continue; + if(g_data["IgnoreTS"].FindValue(unitname) >= 0) continue; #endif WCHAR* addedString=Map->GetUnitName(unitname); @@ -938,75 +957,74 @@ void CViewObjects::UpdateDialog() TV_InsertItemW(tree.m_hWnd, addedString, wcslen(addedString), TVI_LAST, rootitems[0], valadded*1+i); //tree.InsertItem(TVIF_PARAM | TVIF_TEXT, addedString, 0,0,0,0, valadded*1+i, rootitems[0], TVI_LAST ); - lv=i; } - lv+=1; // okay, now the user-defined types: - for(i=0;iGetLength()==0) continue; - - if(strlen(ini.sections[*ini.sections["InfantryTypes"].GetValue(i)].values["Name"])>0) - tree.InsertItem(TVIF_PARAM | TVIF_TEXT, ini.sections[*ini.sections["InfantryTypes"].GetValue(i)].values["Name"], 0,0,0,0, valadded*1+rules.sections["InfantryTypes"].values.size()+i, rootitems[0], TVI_LAST ); - else - tree.InsertItem(TVIF_PARAM | TVIF_TEXT, (*ini.sections["InfantryTypes"].GetValue(i)+" NOTDEFINED"), 0,0,0,0, valadded*1+rules.sections["InfantryTypes"].values.size()+i, rootitems[0], TVI_LAST ); - + auto const& infTypeSec = ini["InfantryTypes"]; + for (i = 0; i < infTypeSec.Size(); i++) { + auto const& id = infTypeSec.Nth(i).second; + if (id.IsEmpty()) { + continue; + } + if (strlen(ini[id]["Name"]) > 0) { + tree.InsertItem(TVIF_PARAM | TVIF_TEXT, ini[id]["Name"], 0, 0, 0, 0, valadded * 1 + rules["InfantryTypes"].Size() + i, rootitems[0], TVI_LAST); + } else { + tree.InsertItem(TVIF_PARAM | TVIF_TEXT, (id + " NOTDEFINED"), 0, 0, 0, 0, valadded * 1 + rules["InfantryTypes"].Size() + i, rootitems[0], TVI_LAST); + } } CString theater=Map->GetTheater(); auto needed_terrain=TheaterChar::None; - if(tiledata==&s_tiledata) needed_terrain=TheaterChar::A; - else if(tiledata==&t_tiledata) needed_terrain=TheaterChar::T; - - for(i=0;iGetTheater()==THEATER0 && g_data.sections["IgnoreTemperateRA2"].FindValue(unitname) >= 0) continue; - if (Map->GetTheater()==THEATER1 && g_data.sections["IgnoreSnowRA2"].FindValue(unitname) >= 0) continue; - if (Map->GetTheater()==THEATER2 && g_data.sections["IgnoreUrbanRA2"].FindValue(unitname) >= 0) continue; - if (Map->GetTheater()==THEATER3 && g_data.sections["IgnoreNewUrbanRA2"].FindValue(unitname) >= 0) continue; - if (Map->GetTheater()==THEATER4 && g_data.sections["IgnoreLunarRA2"].FindValue(unitname) >= 0) continue; - if (Map->GetTheater()==THEATER5 && g_data.sections["IgnoreDesertRA2"].FindValue(unitname) >= 0) continue; + if (Map->GetTheater()==THEATER0 && g_data["IgnoreTemperateRA2"].FindValue(unitname) >= 0) continue; + if (Map->GetTheater()==THEATER1 && g_data["IgnoreSnowRA2"].FindValue(unitname) >= 0) continue; + if (Map->GetTheater()==THEATER2 && g_data["IgnoreUrbanRA2"].FindValue(unitname) >= 0) continue; + if (Map->GetTheater()==THEATER3 && g_data["IgnoreNewUrbanRA2"].FindValue(unitname) >= 0) continue; + if (Map->GetTheater()==THEATER4 && g_data["IgnoreLunarRA2"].FindValue(unitname) >= 0) continue; + if (Map->GetTheater()==THEATER5 && g_data["IgnoreDesertRA2"].FindValue(unitname) >= 0) continue; #else - if (Map->GetTheater()==THEATER0 && g_data.sections["IgnoreTemperateTS"].FindValue(unitname) >= 0) continue; - if (Map->GetTheater()==THEATER1 && g_data.sections["IgnoreSnowTS"].FindValue(unitname) >= 0) continue; + if (Map->GetTheater()==THEATER0 && g_data["IgnoreTemperateTS"].FindValue(unitname) >= 0) continue; + if (Map->GetTheater()==THEATER1 && g_data["IgnoreSnowTS"].FindValue(unitname) >= 0) continue; #endif #ifdef RA2_MODE - if (g_data.sections["IgnoreRA2"].FindValue(unitname) >= 0) continue; + if (g_data["IgnoreRA2"].FindValue(unitname) >= 0) continue; #else - if (g_data.sections["IgnoreTS"].FindValue(unitname) >= 0) continue; + if (g_data["IgnoreTS"].FindValue(unitname) >= 0) continue; #endif - if (!isTrue(g_data.sections["Debug"].GetValueByName("ShowBuildingsWithToTile", "0")) && !rules.sections[unitname].GetValueByName("ToTile").IsEmpty()) + if (!g_data.GetBool("Debug", "ShowBuildingsWithToTile") && !rules[unitname]["ToTile"].IsEmpty()) { continue; - + } WCHAR* addedString=Map->GetUnitName(unitname); - if(!addedString) continue; + if (!addedString) { + continue; + } - - - CString owner=rules.sections[unitname].values["Owner"]; + CString owner=rules[unitname]["Owner"]; int baseplanningside=-1; #ifdef RA2_MODE baseplanningside=-1; #endif - if(rules.sections[unitname].values.find("AIBasePlanningSide")!=rules.sections[unitname].values.end()) - { - baseplanningside=atoi(rules.sections[unitname].values["AIBasePlanningSide"]); - } - if(g_data.sections.find(unitname)!=g_data.sections.end() && g_data.sections[unitname].values.find("AIBasePlanningSide")!=g_data.sections[unitname].values.end()) - { - baseplanningside=atoi(g_data.sections[unitname].values["AIBasePlanningSide"]); - } + baseplanningside = rules.GetInteger(unitname, "AIBasePlanningSide", baseplanningside); + baseplanningside = g_data.GetInteger(unitname, "AIBasePlanningSide", baseplanningside); int id=Map->GetBuildingID(unitname); @@ -1018,11 +1036,7 @@ void CViewObjects::UpdateDialog() if(theater==THEATER2 && !buildinginfo[id].bUrban) { /*MessageBox("Ignored", unitname,0);*/ continue;} // check if mapfile contains other value for owner - if(ini.sections.find(unitname)!=ini.sections.end()) - { - if(ini.sections[unitname].values.find("Owner")!=ini.sections[unitname].values.end()) - owner=ini.sections[unitname].values["Owner"]; - } + owner = ini.GetStringOr(unitname, "Owner", owner); //addedString=TranslateStringACP(addedString); @@ -1058,32 +1072,33 @@ void CViewObjects::UpdateDialog() } - if(bAdded==FALSE) - { + if(bAdded==FALSE) { //tree.InsertItem(TVIF_PARAM | TVIF_TEXT, addedString, 0,0,0,0, valadded*2+i, structhouses[e+1], TVI_LAST ); TV_InsertItemW(tree.m_hWnd, addedString, wcslen(addedString), TVI_LAST, structhouses[sides.size()], valadded*2+i); } - - lv=i; } - lv+=1; - // okay, now the user-defined types: - for(i=0;iGetLength()==0) continue; - int id=Map->GetBuildingID(*ini.sections["BuildingTypes"].GetValue(i)); - if(id<0 || (buildinginfo[id].pic[0].bTerrain!=TheaterChar::None && buildinginfo[id].pic[0].bTerrain!=needed_terrain)) + // okay, now the user-defined types: + auto const& localbldTypeSec = ini["BuildingTypes"]; + for (i = 0; i < localbldTypeSec.Size(); i++) { + auto const& typeId = localbldTypeSec.Nth(i).second; + if (localbldTypeSec.Nth(i).second.IsEmpty()) { continue; + } + + int id = Map->GetBuildingID(typeId); + if (id < 0 || (buildinginfo[id].pic[0].bTerrain != TheaterChar::None && buildinginfo[id].pic[0].bTerrain != needed_terrain)) { + continue; + } int e=2; - CString owner; BOOL bAdded=FALSE; - owner=ini.sections[*ini.sections["BuildingTypes"].GetValue(i)].values["Owner"]; + auto owner=ini[typeId]["Owner"]; owner.MakeUpper(); - if(strlen(ini.sections[*ini.sections["BuildingTypes"].GetValue(i)].values["Name"])>0) - { - CString addedString=ini.sections[*ini.sections["BuildingTypes"].GetValue(i)].values["Name"]; + + auto const& name = ini[typeId]["Name"]; + if(!name.IsEmpty()) { + auto const& addedString = name; int e; for(e=0;eGetTheater()==THEATER0 && g_data.sections["IgnoreTemperateRA2"].FindValue(unitname) >= 0) continue; - if (Map->GetTheater()==THEATER1 && g_data.sections["IgnoreSnowRA2"].FindValue(unitname) >= 0) continue; - if (Map->GetTheater()==THEATER2 && g_data.sections["IgnoreUrbanRA2"].FindValue(unitname) >= 0) continue; - if (Map->GetTheater()==THEATER3 && g_data.sections["IgnoreNewUrbanRA2"].FindValue(unitname) >= 0) continue; - if (Map->GetTheater()==THEATER4 && g_data.sections["IgnoreLunarRA2"].FindValue(unitname) >= 0) continue; - if (Map->GetTheater()==THEATER5 && g_data.sections["IgnoreDesertRA2"].FindValue(unitname) >= 0) continue; + if (Map->GetTheater()==THEATER0 && g_data["IgnoreTemperateRA2"].FindValue(unitname) >= 0) continue; + if (Map->GetTheater()==THEATER1 && g_data["IgnoreSnowRA2"].FindValue(unitname) >= 0) continue; + if (Map->GetTheater()==THEATER2 && g_data["IgnoreUrbanRA2"].FindValue(unitname) >= 0) continue; + if (Map->GetTheater()==THEATER3 && g_data["IgnoreNewUrbanRA2"].FindValue(unitname) >= 0) continue; + if (Map->GetTheater()==THEATER4 && g_data["IgnoreLunarRA2"].FindValue(unitname) >= 0) continue; + if (Map->GetTheater()==THEATER5 && g_data["IgnoreDesertRA2"].FindValue(unitname) >= 0) continue; #else - if (Map->GetTheater()==THEATER0 && g_data.sections["IgnoreTemperateTS"].FindValue(unitname) >= 0) continue; - if (Map->GetTheater()==THEATER1 && g_data.sections["IgnoreSnowTS"].FindValue(unitname) >= 0) continue; + if (Map->GetTheater()==THEATER0 && g_data["IgnoreTemperateTS"].FindValue(unitname) >= 0) continue; + if (Map->GetTheater()==THEATER1 && g_data["IgnoreSnowTS"].FindValue(unitname) >= 0) continue; #endif #ifdef RA2_MODE - if (g_data.sections["IgnoreRA2"].FindValue(unitname) >= 0) continue; + if (g_data["IgnoreRA2"].FindValue(unitname) >= 0) continue; #else - if (g_data.sections["IgnoreTS"].FindValue(unitname) >= 0) continue; + if (g_data["IgnoreTS"].FindValue(unitname) >= 0) continue; #endif WCHAR* addedString=Map->GetUnitName(unitname); @@ -1161,44 +1176,47 @@ void CViewObjects::UpdateDialog() TV_InsertItemW(tree.m_hWnd, addedString, wcslen(addedString), TVI_LAST, rootitems[2], valadded*3+i); //tree.InsertItem(TVIF_PARAM | TVIF_TEXT, addedString, 0,0,0,0, valadded*3+i, rootitems[2], TVI_LAST ); - lv=i; } - lv+=1; + // okay, now the user-defined types: - for(i=0;iGetLength()==0) continue; - - if(strlen(ini.sections[*ini.sections["AircraftTypes"].GetValue(i)].values["Name"])>0) - tree.InsertItem(TVIF_PARAM | TVIF_TEXT, ini.sections[*ini.sections["AircraftTypes"].GetValue(i)].values["Name"], 0,0,0,0, valadded*3+i+rules.sections["AircraftTypes"].values.size(), rootitems[2], TVI_LAST ); - else - tree.InsertItem(TVIF_PARAM | TVIF_TEXT, (*ini.sections["AircraftTypes"].GetValue(i)+" NOTDEFINED"), 0,0,0,0, valadded*3+i+rules.sections["AircraftTypes"].values.size(), rootitems[2], TVI_LAST ); - + auto const localAircraftTypeSec = ini["AircraftTypes"]; + for (i = 0; i < localAircraftTypeSec.Size(); i++) { + auto const& typeId = localAircraftTypeSec.Nth(i).second; + if (typeId.IsEmpty()) { + continue; + } + auto const& name = ini[typeId]["Name"]; + if (!name.IsEmpty()) { + tree.InsertItem(TVIF_PARAM | TVIF_TEXT, name, 0, 0, 0, 0, valadded * 3 + i + rules["AircraftTypes"].Size(), rootitems[2], TVI_LAST); + } else { + tree.InsertItem(TVIF_PARAM | TVIF_TEXT, (typeId + " NOTDEFINED"), 0, 0, 0, 0, valadded * 3 + i + rules["AircraftTypes"].Size(), rootitems[2], TVI_LAST); + } } - for(i=0;iGetTheater()==THEATER0 && g_data.sections["IgnoreTemperateRA2"].FindValue(unitname) >= 0) continue; - if (Map->GetTheater()==THEATER1 && g_data.sections["IgnoreSnowRA2"].FindValue(unitname) >= 0) continue; - if (Map->GetTheater()==THEATER2 && g_data.sections["IgnoreUrbanRA2"].FindValue(unitname) >= 0) continue; - if (Map->GetTheater()==THEATER3 && g_data.sections["IgnoreNewUrbanRA2"].FindValue(unitname) >= 0) continue; - if (Map->GetTheater()==THEATER4 && g_data.sections["IgnoreLunarRA2"].FindValue(unitname) >= 0) continue; - if (Map->GetTheater()==THEATER5 && g_data.sections["IgnoreDesertRA2"].FindValue(unitname) >= 0) continue; + if (Map->GetTheater()==THEATER0 && g_data["IgnoreTemperateRA2"].FindValue(unitname) >= 0) continue; + if (Map->GetTheater()==THEATER1 && g_data["IgnoreSnowRA2"].FindValue(unitname) >= 0) continue; + if (Map->GetTheater()==THEATER2 && g_data["IgnoreUrbanRA2"].FindValue(unitname) >= 0) continue; + if (Map->GetTheater()==THEATER3 && g_data["IgnoreNewUrbanRA2"].FindValue(unitname) >= 0) continue; + if (Map->GetTheater()==THEATER4 && g_data["IgnoreLunarRA2"].FindValue(unitname) >= 0) continue; + if (Map->GetTheater()==THEATER5 && g_data["IgnoreDesertRA2"].FindValue(unitname) >= 0) continue; #else - if (Map->GetTheater()==THEATER0 && g_data.sections["IgnoreTemperateTS"].FindValue(unitname) >= 0) continue; - if (Map->GetTheater()==THEATER1 && g_data.sections["IgnoreSnowTS"].FindValue(unitname) >= 0) continue; + if (Map->GetTheater()==THEATER0 && g_data["IgnoreTemperateTS"].FindValue(unitname) >= 0) continue; + if (Map->GetTheater()==THEATER1 && g_data["IgnoreSnowTS"].FindValue(unitname) >= 0) continue; #endif #ifdef RA2_MODE - if (g_data.sections["IgnoreRA2"].FindValue(unitname) >= 0) continue; + if (g_data["IgnoreRA2"].FindValue(unitname) >= 0) continue; #else - if (g_data.sections["IgnoreTS"].FindValue(unitname) >= 0) continue; + if (g_data["IgnoreTS"].FindValue(unitname) >= 0) continue; #endif WCHAR* addedString=Map->GetUnitName(unitname); @@ -1212,20 +1230,20 @@ void CViewObjects::UpdateDialog() TV_InsertItemW(tree.m_hWnd, addedString, wcslen(addedString), TVI_LAST, rootitems[1], valadded*4+i); //tree.InsertItem(TVIF_PARAM | TVIF_TEXT, addedString, 0,0,0,0, valadded*4+i, rootitems[1], TVI_LAST ); - lv=i; } - lv+=1; // okay, now the user-defined types: - for(i=0;iGetLength()==0) continue; - - if(strlen(ini.sections[*ini.sections["VehicleTypes"].GetValue(i)].values["Name"])>0) - tree.InsertItem(TVIF_PARAM | TVIF_TEXT, ini.sections[*ini.sections["VehicleTypes"].GetValue(i)].values["Name"], 0,0,0,0, valadded*4+i+rules.sections["VehicleTypes"].values.size(), rootitems[1], TVI_LAST ); - else - tree.InsertItem(TVIF_PARAM | TVIF_TEXT, (*ini.sections["VehicleTypes"].GetValue(i)+" NOTDEFINED"), 0,0,0,0, valadded*4+i+rules.sections["VehicleTypes"].values.size(), rootitems[1], TVI_LAST ); - - + auto const localVehTypeSec = ini["VehicleTypes"]; + for (i = 0; i < localVehTypeSec.Size(); i++) { + auto const& typeId = localVehTypeSec.Nth(i).second; + if (typeId.IsEmpty()) { + continue; + } + auto const& name = ini[typeId]["Name"]; + if (!name.IsEmpty()) { + tree.InsertItem(TVIF_PARAM | TVIF_TEXT, name, 0, 0, 0, 0, valadded * 4 + i + rules["VehicleTypes"].Size(), rootitems[1], TVI_LAST); + } else { + tree.InsertItem(TVIF_PARAM | TVIF_TEXT, (typeId + " NOTDEFINED"), 0, 0, 0, 0, valadded * 4 + i + rules["VehicleTypes"].Size(), rootitems[1], TVI_LAST); + } } @@ -1243,32 +1261,32 @@ void CViewObjects::UpdateDialog() tree.InsertItem(TVIF_PARAM | TVIF_TEXT, GetLanguageStringACP("RndTreeObList"), 0,0,0,0, valadded*5+999, rootitems[4], TVI_LAST); #endif - for(i=0;iGetUnitName(unitname); #ifdef RA2_MODE - if (Map->GetTheater()==THEATER0 && g_data.sections["IgnoreTemperateRA2"].FindValue(unitname) >= 0) continue; - if (Map->GetTheater()==THEATER1 && g_data.sections["IgnoreSnowRA2"].FindValue(unitname) >= 0) continue; - if (Map->GetTheater()==THEATER2 && g_data.sections["IgnoreUrbanRA2"].FindValue(unitname) >= 0) continue; - if (Map->GetTheater()==THEATER3 && g_data.sections["IgnoreNewUrbanRA2"].FindValue(unitname) >= 0) continue; - if (Map->GetTheater()==THEATER4 && g_data.sections["IgnoreLunarRA2"].FindValue(unitname) >= 0) continue; - if (Map->GetTheater()==THEATER5 && g_data.sections["IgnoreDesertRA2"].FindValue(unitname) >= 0) continue; + if (Map->GetTheater()==THEATER0 && g_data["IgnoreTemperateRA2"].FindValue(unitname) >= 0) continue; + if (Map->GetTheater()==THEATER1 && g_data["IgnoreSnowRA2"].FindValue(unitname) >= 0) continue; + if (Map->GetTheater()==THEATER2 && g_data["IgnoreUrbanRA2"].FindValue(unitname) >= 0) continue; + if (Map->GetTheater()==THEATER3 && g_data["IgnoreNewUrbanRA2"].FindValue(unitname) >= 0) continue; + if (Map->GetTheater()==THEATER4 && g_data["IgnoreLunarRA2"].FindValue(unitname) >= 0) continue; + if (Map->GetTheater()==THEATER5 && g_data["IgnoreDesertRA2"].FindValue(unitname) >= 0) continue; #else - if (Map->GetTheater()==THEATER0 && g_data.sections["IgnoreTemperateTS"].FindValue(unitname) >= 0) continue; - if (Map->GetTheater()==THEATER1 && g_data.sections["IgnoreSnowTS"].FindValue(unitname) >= 0) continue; + if (Map->GetTheater()==THEATER0 && g_data["IgnoreTemperateTS"].FindValue(unitname) >= 0) continue; + if (Map->GetTheater()==THEATER1 && g_data["IgnoreSnowTS"].FindValue(unitname) >= 0) continue; #endif #ifdef RA2_MODE - if (g_data.sections["IgnoreRA2"].FindValue(unitname) >= 0) continue; + if (g_data["IgnoreRA2"].FindValue(unitname) >= 0) continue; #else - if (g_data.sections["IgnoreTS"].FindValue(unitname) >= 0) continue; + if (g_data["IgnoreTS"].FindValue(unitname) >= 0) continue; #endif #ifdef RA2_MODE - if (g_data.sections["IgnoreTerrainRA2"].FindValue(unitname) >= 0) continue; + if (g_data["IgnoreTerrainRA2"].FindValue(unitname) >= 0) continue; #else - if (g_data.sections["IgnoreTerrainTS"].FindValue(unitname) >= 0) continue; + if (g_data["IgnoreTerrainTS"].FindValue(unitname) >= 0) continue; #endif addedString=TranslateStringACP(addedString); @@ -1287,8 +1305,8 @@ void CViewObjects::UpdateDialog() #ifdef RA2_MODE if(howner==hTrees) { - int TreeMin=atoi(g_data.sections[Map->GetTheater()+"Limits"].values["TreeMin"]); - int TreeMax=atoi(g_data.sections[Map->GetTheater()+"Limits"].values["TreeMax"]); + int TreeMin=atoi(g_data[Map->GetTheater()+"Limits"]["TreeMin"]); + int TreeMax=atoi(g_data[Map->GetTheater()+"Limits"]["TreeMax"]); CString id=unitname; id.Delete(0, 4); @@ -1300,32 +1318,30 @@ void CViewObjects::UpdateDialog() if(unitname.GetLength()>0 && unitname!="VEINTREE" && unitname.Find("ICE")<0 && unitname.Find("BOXES")<0 && unitname.Find("SPKR")<0) // out with it :-) tree.InsertItem(TVIF_PARAM | TVIF_TEXT, (addedString+ " (" + unitname +")"), 0,0,0,0, valadded*5+i, howner, TVI_LAST ); - - lv=i; } #ifdef SMUDGE_SUPP - for(i=0;iGetTheater()==THEATER0 && g_data.sections["IgnoreTemperateRA2"].FindValue(unitname) >= 0) continue; - if (Map->GetTheater()==THEATER1 && g_data.sections["IgnoreSnowRA2"].FindValue(unitname) >= 0) continue; - if (Map->GetTheater()==THEATER2 && g_data.sections["IgnoreUrbanRA2"].FindValue(unitname) >= 0) continue; - if (Map->GetTheater()==THEATER3 && g_data.sections["IgnoreNewUrbanRA2"].FindValue(unitname) >= 0) continue; - if (Map->GetTheater()==THEATER4 && g_data.sections["IgnoreLunarRA2"].FindValue(unitname) >= 0) continue; - if (Map->GetTheater()==THEATER5 && g_data.sections["IgnoreDesertRA2"].FindValue(unitname) >= 0) continue; + if (Map->GetTheater()==THEATER0 && g_data["IgnoreTemperateRA2"].FindValue(unitname) >= 0) continue; + if (Map->GetTheater()==THEATER1 && g_data["IgnoreSnowRA2"].FindValue(unitname) >= 0) continue; + if (Map->GetTheater()==THEATER2 && g_data["IgnoreUrbanRA2"].FindValue(unitname) >= 0) continue; + if (Map->GetTheater()==THEATER3 && g_data["IgnoreNewUrbanRA2"].FindValue(unitname) >= 0) continue; + if (Map->GetTheater()==THEATER4 && g_data["IgnoreLunarRA2"].FindValue(unitname) >= 0) continue; + if (Map->GetTheater()==THEATER5 && g_data["IgnoreDesertRA2"].FindValue(unitname) >= 0) continue; #else - if (Map->GetTheater()==THEATER0 && g_data.sections["IgnoreTemperateTS"].FindValue(unitname) >= 0) continue; - if (Map->GetTheater()==THEATER1 && g_data.sections["IgnoreSnowTS"].FindValue(unitname) >= 0) continue; + if (Map->GetTheater()==THEATER0 && g_data["IgnoreTemperateTS"].FindValue(unitname) >= 0) continue; + if (Map->GetTheater()==THEATER1 && g_data["IgnoreSnowTS"].FindValue(unitname) >= 0) continue; #endif #ifdef RA2_MODE - if (g_data.sections["IgnoreRA2"].FindValue(unitname) >= 0) continue; + if (g_data["IgnoreRA2"].FindValue(unitname) >= 0) continue; #else - if (g_data.sections["IgnoreTS"].FindValue(unitname) >= 0) continue; + if (g_data["IgnoreTS"].FindValue(unitname) >= 0) continue; #endif addedString=TranslateStringACP(addedString); @@ -1335,10 +1351,9 @@ void CViewObjects::UpdateDialog() HTREEITEM howner=rootitems[14]; - if(unitname.GetLength()>0) - tree.InsertItem(TVIF_PARAM | TVIF_TEXT, unitname, 0,0,0,0, valadded*8+i, howner, TVI_LAST ); - - lv=i; + if (unitname.GetLength() > 0) { + tree.InsertItem(TVIF_PARAM | TVIF_TEXT, unitname, 0, 0, 0, 0, valadded * 8 + i, howner, TVI_LAST); + } } #endif @@ -1384,22 +1399,19 @@ void CViewObjects::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) void CViewObjects::HandleBrushSize(int iTile) { - if(iTile>=*tiledata_count) return; + if (iTile >= *tiledata_count) { + return; + } - int i; - for(i=0;i=0) - { - int tset=atoi((*tiles).sections["General"].values[n]); - if(tset==(*tiledata)[iTile].wTileSet) - { - int bs=atoi(*g_data.sections["StdBrushSize"].GetValue(i)); - ((CFinalSunDlg*)theApp.m_pMainWnd)->m_settingsbar.m_BrushSize=bs-1; + for (auto const& [n, val] : g_data["StdBrushSize"]) { + if ((*tiles)["General"].FindIndex(n) >= 0) { + int tset = tiles->GetInteger("General", n); + if (tset == (*tiledata)[iTile].wTileSet) { + int bs = atoi(val); + ((CFinalSunDlg*)theApp.m_pMainWnd)->m_settingsbar.m_BrushSize = bs - 1; ((CFinalSunDlg*)theApp.m_pMainWnd)->m_settingsbar.UpdateData(FALSE); - ((CFinalSunDlg*)theApp.m_pMainWnd)->m_view.m_isoview->m_BrushSize_x=bs; - ((CFinalSunDlg*)theApp.m_pMainWnd)->m_view.m_isoview->m_BrushSize_y=bs; + ((CFinalSunDlg*)theApp.m_pMainWnd)->m_view.m_isoview->m_BrushSize_x = bs; + ((CFinalSunDlg*)theApp.m_pMainWnd)->m_view.m_isoview->m_BrushSize_y = bs; } } } diff --git a/MissionEditor/ViewObjects.h b/MissionEditor/ViewObjects.h index a431e83..f48c04b 100644 --- a/MissionEditor/ViewObjects.h +++ b/MissionEditor/ViewObjects.h @@ -28,7 +28,39 @@ // #include +#define MAKE_MASK(refVal) 1 << static_cast(refVal) +enum class TreeViewTechnoType { + Set_None = -1, + Building = 0, + Infantry, + Vehicle, + Aircraft, + _Last, + _First = 0, + Count = _Last, +}; + +enum class TechnoTypeMask +{ + ForBuilding = MAKE_MASK(TreeViewTechnoType::Building), + ForInfantry = MAKE_MASK(TreeViewTechnoType::Infantry), + ForVehicle = MAKE_MASK(TreeViewTechnoType::Vehicle), + ForAircraft = MAKE_MASK(TreeViewTechnoType::Aircraft), +}; + +inline bool operator&(TechnoTypeMask lhs, TechnoTypeMask rhs) +{ + return static_cast(lhs) & static_cast(rhs); +} +inline bool operator&(TechnoTypeMask lhs, TreeViewTechnoType rhs) +{ + return lhs & static_cast(MAKE_MASK(rhs)); +} +inline bool operator&(TreeViewTechnoType lhs, TechnoTypeMask rhs) +{ + return rhs & static_cast(MAKE_MASK(lhs)); +} ///////////////////////////////////////////////////////////////////////////// // Ansicht CViewObjects diff --git a/MissionEditor/WaypointID.cpp b/MissionEditor/WaypointID.cpp index 8d59d70..4496e89 100644 --- a/MissionEditor/WaypointID.cpp +++ b/MissionEditor/WaypointID.cpp @@ -71,13 +71,12 @@ void CWaypointID::OnFree() int i; CString freen; - for(i=0;i>-1;i++) + for (i = 0; i > -1; i++) { char d[50]; - itoa(i,d,10); - if(ini.sections["Waypoints"].values.find(d)==ini.sections["Waypoints"].values.end()) - { - freen=d; + itoa(i, d, 10); + if (ini.GetString("Waypoints", d).IsEmpty()) { + freen = d; break; } } diff --git a/MissionEditor/functions.cpp b/MissionEditor/functions.cpp index 4974653..40bb6e7 100644 --- a/MissionEditor/functions.cpp +++ b/MissionEditor/functions.cpp @@ -28,6 +28,7 @@ #include "inlines.h" #include "mmsystem.h" +#include #define DBG #undef DBG @@ -146,22 +147,14 @@ char *strcpy_safe( char *strDestination, const char *strSource ) CString TranslateHouse(CString original, BOOL bToUI) { #ifdef RA2_MODE - if(bToUI) - { + if(bToUI) { // CCStrings[*rules.sections[HOUSES].GetValue(i)].wString - int i; - for(i=0;i=0) - { - CString s=language.sections["English-StringsRA2"].values[name]; - return ToACP(s); - } + auto const strRA2Sec = theApp.m_Options.LanguageName + "-StringsRA2"; + if (auto const& translated = language.GetSection(strRA2Sec).TryGetString(name)) { + return ToACP(*translated); + } + if(auto const& def = language.GetSection("English-StringsRA2").TryGetString(name)) { + return ToACP(*def); } - else - return ToACP(language.sections[sec2].values[name]); #endif - - - if(language.sections[theApp.m_Options.LanguageName+"-Strings"].values.find(name)==language.sections[theApp.m_Options.LanguageName+"-Strings"].values.end()) - { - CString s=language.sections["English-Strings"].values[name]; + auto const defSec = theApp.m_Options.LanguageName + "-Strings"; + auto const translated = language.GetSection(defSec).TryGetString(name); + if(!translated) { + CString s = language.GetSection("English-Strings").GetStringOr(name, name); #ifndef RA2_MODE - s=TranslateStringVariables(9, s, "FinalSun"); + s = TranslateStringVariables(9, s, "FinalSun"); #else #ifdef YR_MODE - s=TranslateStringVariables(9, s, "FinalAlert 2: Yuri's Revenge"); + s = TranslateStringVariables(9, s, "FinalAlert 2: Yuri's Revenge"); #else - s=TranslateStringVariables(9, s, "FinalAlert 2"); + s = TranslateStringVariables(9, s, "FinalAlert 2"); #endif #endif return ToACP(s); } CString s; - s= language.sections[theApp.m_Options.LanguageName+"-Strings"].values[name]; + s = *translated; #ifndef RA2_MODE - if(s.Find("%9")>=0) s=TranslateStringVariables(9,s,"FinalSun"); + if (s.Find("%9") >= 0) s = TranslateStringVariables(9, s, "FinalSun"); #else #ifdef YR_MODE - if(s.Find("%9")>=0) s=TranslateStringVariables(9,s,"FinalAlert 2: Yuri's Revenge"); + if (s.Find("%9") >= 0) s = TranslateStringVariables(9, s, "FinalAlert 2: Yuri's Revenge"); #else - if(s.Find("%9")>=0) s=TranslateStringVariables(9,s,"FinalAlert 2"); + if (s.Find("%9") >= 0) s = TranslateStringVariables(9, s, "FinalAlert 2"); #endif #endif @@ -472,71 +474,11 @@ CString TranslateStringACP(WCHAR* u16EnglishString) // tranlate a string/word by using the table from english to the current language CString TranslateStringACP(CString u8EnglishString) { - if (!isValidUtf8(u8EnglishString)) - { + if (!isValidUtf8(u8EnglishString)) { errstream << "TranslateStringACP(\"" << u8EnglishString << "\") called with an invalid UTF-8 string" << std::endl; return u8EnglishString; } - -#ifdef RA2_MODE - CString sec2=theApp.m_Options.LanguageName+"-TranslationsRA2"; - if(language.sections[sec2].values.end()==language.sections[sec2].values.find(u8EnglishString)) - { - if(language.sections["English-TranslationsRA2"].FindName(u8EnglishString)>=0) - { - CString s=language.sections["English-TranslationsRA2"].values[u8EnglishString]; - return ToACP(s); - } - } - else - return ToACP(language.sections[sec2].values[u8EnglishString]); -#endif - - - CString sec=theApp.m_Options.LanguageName+"-Translations"; - - // check if the string can be translated - if(language.sections[sec].values.end()==language.sections[sec].values.find(u8EnglishString)) - { - CString seceng; - seceng="English-Translations"; - if(language.sections[seceng].FindName(u8EnglishString)>=0) - { - CString s=language.sections[seceng].values[u8EnglishString]; -#ifndef RA2_MODE - s=TranslateStringVariables(9, s, "FinalSun"); -#else -#ifdef YR_MODE - s=TranslateStringVariables(9, s, "FinalAlert 2: Yuri's Revenge"); -#else - s=TranslateStringVariables(9, s, "FinalAlert 2"); -#endif -#endif - return ToACP(s); - } -#ifndef RA2_MODE - return ToACP(TranslateStringVariables(9,u8EnglishString,"FinalSun")); -#else -#ifdef YR_MODE - return ToACP(TranslateStringVariables(9,u8EnglishString,"FinalAlert 2: Yuri's Revenge")); -#else - return ToACP(TranslateStringVariables(9,u8EnglishString,"FinalAlert 2")); -#endif -#endif - } - - CString s=language.sections[sec].values[u8EnglishString]; -#ifndef RA2_MODE - s=TranslateStringVariables(9,s,"FinalSun"); -#else -#ifdef YR_MODE - s=TranslateStringVariables(9,s,"FinalAlert 2: Yuri's Revenge"); -#else - s=TranslateStringVariables(9,s,"FinalAlert 2"); -#endif -#endif - - return ToACP(s); + return GetLanguageStringACP(u8EnglishString); } @@ -766,210 +708,100 @@ std::array HSVToRGB(const unsigned char hsv[3]) return ret; } -void ListBuildings(CComboBox& cb, BOOL bININame) +void listSpecifcTechnoTypes(CComboBox& cb, const CString& sectionName, bool clear = true, bool useIniName = false) { - while(cb.DeleteString(0)!=CB_ERR); + if (clear) { + while (cb.DeleteString(0) != CB_ERR); + } + auto const& sec = rules.GetSection(sectionName); + for (auto idx = 0; idx < sec.Size(); ++idx) { + char idxNum[50]; + itoa(idx, idxNum, 10); + CString record = idxNum; - int i; - for(i=0;iGetUnitName(*rules.sections["BuildingTypes"].GetValue(i)); - - if(bININame) s=*rules.sections["BuildingTypes"].GetValue(i); - - s+=" "; + if (useIniName) { + record = kvPair.second; + } + record += " "; - CString t=Map->GetUnitName(*rules.sections["BuildingTypes"].GetValue(i)); + CString translated = Map->GetUnitName(kvPair.second); //if(t!="MISSING") { - s+=t; - cb.AddString(s); + record += translated; + cb.AddString(record); } } } +void listSpecifcTypesWithSequence(CComboBox& cb, const CString& sectionName, bool clear = true) { + if (clear) { + while (cb.DeleteString(0) != CB_ERR); + } + auto const& sec = rules.GetSection(sectionName); + for (auto idx = 0; idx < sec.Size(); ++idx) { + char idxNum[50]; + itoa(idx, idxNum, 10); + auto const& kvPair = sec.Nth(idx); + CString record = idxNum; + record += " "; + record += kvPair.second; + cb.AddString(record); + } +} + +void ListBuildings(CComboBox& cb, bool bININame) +{ + listSpecifcTechnoTypes(cb, "BuildingTypes", true, bININame); +} + void ListInfantry(CComboBox& cb) { - while(cb.DeleteString(0)!=CB_ERR); - int i; - for(i=0;iGetUnitName(*rules.sections["InfantryTypes"].GetValue(i)); - CString t=Map->GetUnitName(*rules.sections["InfantryTypes"].GetValue(i)); - //if(t!="MISSING") - { - s+=t; - cb.AddString(s); - } - } + listSpecifcTechnoTypes(cb, "InfantryTypes"); } void ListUnits(CComboBox& cb) { - while(cb.DeleteString(0)!=CB_ERR); - int i; - for(i=0;iGetUnitName(*rules.sections["VehicleTypes"].GetValue(i)); - //if(t!="MISSING") - { - s+=t; - cb.AddString(s); - } - } + listSpecifcTechnoTypes(cb, "VehicleTypes"); } void ListAircraft(CComboBox& cb) { - while(cb.DeleteString(0)!=CB_ERR); - int i; - for(i=0;iGetUnitName(*rules.sections["AircraftTypes"].GetValue(i)); - //if(t!="MISSING") - { - s+=t; - cb.AddString(s); - } - } + listSpecifcTechnoTypes(cb, "AircraftTypes"); } void ListTechtypes(CComboBox& cb) { - while(cb.DeleteString(0)!=CB_ERR); - int i; - for(i=0;iGetUnitName(*rules.sections["AircraftTypes"].GetValue(i)); - //if(t!="MISSING") - { - s+=t; - cb.AddString(s); - } - } - for(i=0;iGetUnitName(*rules.sections["InfantryTypes"].GetValue(i)); - //if(t!="MISSING") - { - s+=t; - cb.AddString(s); - } - } - for(i=0;iGetUnitName(*rules.sections["VehicleTypes"].GetValue(i)); - //if(t!="MISSING") - { - s+=t; - cb.AddString(s); - } - } - for(i=0;iGetUnitName(*rules.sections["BuildingTypes"].GetValue(i)); - //if(t!="MISSING") - { - s+=t; - cb.AddString(s); - } + for (auto const& kvPair : ini.GetSection("VariableNames")) { + auto const desc = kvPair.first + " " + kvPair.second; + cb.AddString(desc); } } // should be ListLocals() void ListGlobals(CComboBox& cb) { - while(cb.DeleteString(0)!=CB_ERR); - int i; - CIniFile& ini=Map->GetIniFile(); - for(i=0;iGetIniFile()); } void ListRulesGlobals(CComboBox& cb) { - while(cb.DeleteString(0)!=CB_ERR); - int i; - for(i=0;i AllStrings; +extern TranslationMap AllStrings; void ListTutorial(CComboBox& cb) { while(cb.DeleteString(0)!=CB_ERR); @@ -1014,22 +846,18 @@ void ListTutorial(CComboBox& cb) void ListTriggers(CComboBox& cb) { - while(cb.DeleteString(0)!=CB_ERR); - int i; - CIniFile& ini=Map->GetIniFile(); - for(i=0;iGetIniFile(); + + for (auto const& kvPair : ini.GetSection("Triggers")) { + auto s = kvPair.first; + s += " ("; + s += GetParam(kvPair.second, 2); + s += ")"; cb.AddString(s); - } + } + } void ListYesNo(CComboBox& cb) @@ -1041,106 +869,57 @@ void ListYesNo(CComboBox& cb) void ListSounds(CComboBox& cb) { - while(cb.DeleteString(0)!=CB_ERR); + while (cb.DeleteString(0) != CB_ERR); #ifdef RA2_MODE - int i; - for(i=0;i"); - for(i=0;i"); } - if(sel>=0) cb.SetCurSel(sel); + auto const& movieList = art.GetSection("Movies"); + for (auto idx = 0; idx < movieList.Size();++idx) { + if (idx < atoi(g_data.GetString("MovieList", "Start"))) { + continue; + } + CString movieID = movieList.Nth(idx).second; + cb.AddString(movieID); + } + if (sel >= 0) { + cb.SetCurSel(sel); + } + return; } - else - { - - while(cb.DeleteString(0)!=CB_ERR); - - int i; - for(i=0;iGetIniFile(); + CIniFile& ini = Map->GetIniFile(); - int sel=cb.GetCurSel(); + int sel = cb.GetCurSel(); - while(cb.DeleteString(0)!=CB_ERR); + while (cb.DeleteString(0) != CB_ERR); int i; - if(bListNone) cb.AddString("None"); - for(i=0;i=0) cb.SetCurSel(sel); + if (sel >= 0) { + cb.SetCurSel(sel); + } } int GetRulesHousesSize() { - int i; - int count=0; - for(i=0;i(); + toDelete.reserve(sec.Size()); - for(i=0;iRemoveAt(idx); + } + } - return count; + return GetRulesHousesSize(); } // MW 07/27/01: Modified for etc in YR @@ -1264,22 +1031,23 @@ void ListHouses(CComboBox &cb, BOOL bNumbers, BOOL bCountries, BOOL bPlayers) { CIniFile& ini=Map->GetIniFile(); - int i; - int sel=cb.GetCurSel(); - int crulesh=GetRulesHousesSize(); + int sel = cb.GetCurSel(); + int crulesh = GetRulesHousesSize(); - if(Map->IsMultiplayer()==FALSE) bPlayers=FALSE; // really only for multi maps! + // TODO: align with RN edition + if (Map->IsMultiplayer() == FALSE) { + bPlayers = FALSE; // really only for multi maps! + } - //for(i=0;iSize() == 0) { + goto wasnohouse; + } // we use the map definitions! if(yuri_mode && bPlayers) @@ -1310,79 +1078,74 @@ void ListHouses(CComboBox &cb, BOOL bNumbers, BOOL bCountries, BOOL bPlayers) } - for(i=0;iSize(); i++) { CString j; #ifdef RA2_MODE - j=*ini.sections[sSection].GetValue(i); + j = mapHouseList->Nth(i).second; j.MakeLower(); - if(j=="nod" || j=="gdi") continue; -#endif + if (j == "nod" || j == "gdi") { + continue; + } +#endif - if(bNumbers) - { - char c[50]; - int n=atoi(*ini.sections[sSection].GetValueName(i)); - itoa(n, c, 10); + if(bNumbers) { + char idxStr[50]; + itoa(i, idxStr, 10); #ifdef RA2_MODE - if(bCountries) - { - int preexisting=0; + if(bCountries) { + int preexisting = 0; int e; - for(e=0;e=0) + auto const& rulesMapList = rules.GetSection(sSection); + for (e = 0; e < i; e++) { + if (rulesMapList.HasValue(mapHouseList->Nth(e).second)) { preexisting++; + } } - if(rules.sections[sSection].FindValue(*ini.sections[sSection].GetValue(i))>=0) - { - itoa(rules.sections[sSection].value_orig_pos[*rules.sections[sSection].GetValueName(rules.sections[sSection].FindValue(*ini.sections[sSection].GetValue(i)))], c, 10); + if (rulesMapList.HasValue(mapHouseList->Nth(i).second)) { + auto const& mapHouseID = mapHouseList->Nth(i).second; + auto const& idxInRules = rulesMapList.FindValue(mapHouseID); + itoa(idxInRules, idxStr, 10); } - else - { - itoa(n+crulesh-preexisting, c, 10); + else { + itoa(i + crulesh - preexisting, idxStr, 10); } } #endif - j=c; - j+=" "; - j+=TranslateHouse(*ini.sections[sSection].GetValue(i), TRUE); + j = idxStr; + j += " "; + j += TranslateHouse(mapHouseList->Nth(i).second, TRUE); + } + else { + j = TranslateHouse(mapHouseList->Nth(i).second, TRUE); } - else - j=TranslateHouse(*ini.sections[sSection].GetValue(i), TRUE); - cb.AddString(j); } } - else - { + else { wasnohouse: - if(bNumbers) - { - - for(i=0;i"); cb.AddString("4476 "); cb.AddString("4477 "); @@ -1412,10 +1174,8 @@ void ListHouses(CComboBox &cb, BOOL bNumbers, BOOL bCountries, BOOL bPlayers) cb.AddString("4482 "); } } - else - { - if(yuri_mode && bPlayers) - { + else { + if(yuri_mode && bPlayers) { cb.AddString(""); cb.AddString(""); cb.AddString(""); @@ -1426,77 +1186,76 @@ void ListHouses(CComboBox &cb, BOOL bNumbers, BOOL bCountries, BOOL bPlayers) cb.AddString(""); } - for(i=0;i=0) cb.SetCurSel(sel); - + if (sel >= 0) { + cb.SetCurSel(sel); + } } void ListTeamTypes(CComboBox &cb, BOOL bListNone) { - CIniFile& ini=Map->GetIniFile(); + CIniFile& ini = Map->GetIniFile(); - int sel=cb.GetCurSel(); + int sel = cb.GetCurSel(); - while(cb.DeleteString(0)!=CB_ERR); + while (cb.DeleteString(0) != CB_ERR); int i; - if(bListNone) cb.AddString(""); - for(i=0;i"); + } + auto const& teamTypeList = ini.GetSection("TeamTypes"); + for (auto const& [seq, id] : teamTypeList) { + auto const& teamTypeDetail = ini.GetSection(id); + CString record = id + " " + teamTypeDetail.GetString("Name"); + cb.AddString(record); } - if(sel>=0) cb.SetCurSel(sel); + if (sel >= 0) { + cb.SetCurSel(sel); + } } void ListWaypoints(CComboBox &cb) { - CIniFile& ini=Map->GetIniFile(); + CIniFile& ini = Map->GetIniFile(); - int sel=cb.GetCurSel(); + int sel = cb.GetCurSel(); - while(cb.DeleteString(0)!=CB_ERR); + while (cb.DeleteString(0) != CB_ERR); - int i; - for(i=0;i=0) cb.SetCurSel(sel); + if (sel >= 0) { + cb.SetCurSel(sel); + } } void ListTargets(CComboBox &cb) @@ -1532,42 +1291,42 @@ CString GetHouseSectionName(CString lpHouse) CString GetFreeID() { - CIniFile& ini=Map->GetIniFile(); + auto const& ini = Map->GetIniFile(); - int n=1000000; - while(TRUE) - { + int n = 1000000; + + auto isIDInUse = [&ini](const CString& input) { + static const CString typeListSections[] = { + "ScriptTypes", + "TaskForces", + "TeamTypes", + }; + static const CString idListSections[] = { + "Triggers", + "Events", + "Tags", + "Actions", + "AITriggerTypes", + }; + if (find(std::begin(typeListSections), std::end(typeListSections), input) != std::end(typeListSections)) { + return true; + } + if (find(std::begin(idListSections), std::end(idListSections), input) != std::end(idListSections)) { + return true; + } + return false; + }; + + for (;;) { char p[50]; - p[0]='0'; - itoa(n,p+1,10); - if(ini.sections["ScriptTypes"].FindValue(p)==-1) - { - if(ini.sections["TaskForces"].FindValue(p)==-1) - { - if(ini.sections["TeamTypes"].FindValue(p)==-1) - { - if(ini.sections["Triggers"].values.find(p)==ini.sections["Triggers"].values.end()) - { - if(ini.sections["Events"].values.find(p)==ini.sections["Events"].values.end()) - { - if(ini.sections["Tags"].values.find(p)==ini.sections["Tags"].values.end()) - { - if(ini.sections["Actions"].values.find(p)==ini.sections["Actions"].values.end()) - { - if(ini.sections["AITriggerTypes"].values.find(p)==ini.sections["AITriggerTypes"].values.end()) - { - if(ini.sections.find(p)==ini.sections.end()) - return p; - } - } - } - } - } - } - } + p[0] = '0'; + itoa(n, p + 1, 10); + + if (!isIDInUse(p)) { + return p; } n++; - } + } return ""; } @@ -1597,74 +1356,72 @@ void GetNodeName(CString & name, int n) name=c; } -int GetNodeAt(CString& owner, CString& type, int x, int y) +int GetNodeAt(CString& owner, CString& buildingTypeID, int x, int y) { - CIniFile& ini=Map->GetIniFile(); + CIniFile& ini = Map->GetIniFile(); - type=""; - owner=""; + buildingTypeID = ""; + owner = ""; int owners; - if(ini.sections.find(HOUSES)!=ini.sections.end()) - { - for(owners=0;owners= 0 && art.sections[UnitName].AccessValueByName("DemandLoad") != "yes") - if (art.sections[UnitName].AccessValueByName("NewTheater") == "yes") - filename.SetAt(1, 'T'); + if (art.GetBool(UnitName, "NewTheater") && !art.GetBool(UnitName, "DemandLoad")) { + filename.SetAt(1, 'T'); + } char n[50]; itoa(dwPicIndex, n, 10); diff --git a/MissionEditor/variables.cpp b/MissionEditor/variables.cpp index 23a36cd..d577172 100644 --- a/MissionEditor/variables.cpp +++ b/MissionEditor/variables.cpp @@ -190,8 +190,8 @@ CFinalSunApp theApp; CString currentOwner="Neutral"; -map CCStrings; -map AllStrings; +TranslationMap CCStrings; +TranslationMap AllStrings; // tilesets int cliffset; diff --git a/MissionEditor/variables.h b/MissionEditor/variables.h index 721ad19..30ec9b0 100644 --- a/MissionEditor/variables.h +++ b/MissionEditor/variables.h @@ -29,6 +29,8 @@ #include "FinalSun.h" #include "MapData.h" +using TranslationMap = map; + // the map extern CMapData* Map; @@ -132,7 +134,7 @@ extern BOOL yr_only[]; extern CString currentOwner; -extern map CCStrings; +extern TranslationMap CCStrings; // tileset ids extern int cliffset; diff --git a/MissionEditorPackLib/MissionEditorPackLib.cpp b/MissionEditorPackLib/MissionEditorPackLib.cpp index d8fc816..c0ddd39 100644 --- a/MissionEditorPackLib/MissionEditorPackLib.cpp +++ b/MissionEditorPackLib/MissionEditorPackLib.cpp @@ -115,12 +115,13 @@ namespace FSunPackLib std::wstring utf8ToUtf16(const std::string& utf8) { // wstring_convert and codecvt_utf8_utf16 are deprecated in C++17, fallback to Win32 - if (utf8.size() == 0) + auto utf8Count = static_cast(utf8.size()); + if (utf8Count == 0) { // MultiByteToWideChar does not support passing in cbMultiByte == 0 return L""; + } // unterminatedCountWChars will be the count of WChars NOT including the terminating zero (due to passing in utf8.size() instead of -1) - auto utf8Count = utf8.size(); auto unterminatedCountWChars = MultiByteToWideChar(CP_UTF8, MB_PRECOMPOSED | MB_ERR_INVALID_CHARS, utf8.data(), utf8Count, nullptr, 0); if (unterminatedCountWChars == 0) { @@ -287,7 +288,7 @@ namespace FSunPackLib return true; } - int DecodeBase64(const char* sp, std::vector& dest) + size_t DecodeBase64(const char* sp, std::vector& dest) { auto len = strlen(reinterpret_cast(sp)); auto res = decode64(data_ref(sp, len)); @@ -1765,7 +1766,7 @@ namespace FSunPackLib Vec3f secMinVec, secMaxVec; GetVXLSectionBounds(i, rotation, postHVAOffset, secMinVec, secMaxVec); auto extent = secMaxVec - secMinVec; - auto volume = extent.x() * extent.y() * extent.z(); + auto volume = static_cast(extent.x() * extent.y() * extent.z()); if (volume >= iLargestVolume) { iLargestVolume = volume; @@ -1785,8 +1786,8 @@ namespace FSunPackLib const auto extents = (maxCoords - minCoords); - int rtWidth = ceil(extents.x()); - int rtHeight = ceil(extents.y()); + int rtWidth = static_cast(ceil(extents.x())); + int rtHeight = static_cast(ceil(extents.y())); const int c_pixels = rtWidth * rtHeight; // MYASSERT(c_pixels,1); @@ -2000,7 +2001,7 @@ namespace FSunPackLib Vec3f secMinVec, secMaxVec; GetVXLSectionBounds(i, rotation, modelOffset, secMinVec, secMaxVec); auto extent = secMaxVec - secMinVec; - auto volume = extent.x() * extent.y() * extent.z(); + auto volume = static_cast(extent.x() * extent.y() * extent.z()); if (volume >= iLargestVolume) { iLargestVolume = volume; @@ -2021,8 +2022,8 @@ namespace FSunPackLib const auto extents = (maxCoords - minCoords); - int rtWidth = ceil(extents.x()) + 1; - int rtHeight = ceil(extents.y()) + 1; + int rtWidth = static_cast(ceil(extents.x()) + 1); + int rtHeight = static_cast(ceil(extents.y()) + 1); const int c_pixels = rtWidth * rtHeight; MYASSERT(c_pixels, 1); diff --git a/MissionEditorPackLib/MissionEditorPackLib.h b/MissionEditorPackLib/MissionEditorPackLib.h index 0e7a50a..dac3524 100644 --- a/MissionEditorPackLib/MissionEditorPackLib.h +++ b/MissionEditorPackLib/MissionEditorPackLib.h @@ -109,7 +109,7 @@ sp - source poINTer dp - dest buffer (should be as large as sp) Returns the hex data length */ - int DecodeBase64(const char* sp, std::vector& dest); + size_t DecodeBase64(const char* sp, std::vector& dest); // format 80 diff --git a/MissionEditorPackLib/MissionEditorPackLib.vcxproj b/MissionEditorPackLib/MissionEditorPackLib.vcxproj index a5a559a..5921876 100644 --- a/MissionEditorPackLib/MissionEditorPackLib.vcxproj +++ b/MissionEditorPackLib/MissionEditorPackLib.vcxproj @@ -5,10 +5,18 @@ Debug Win32 + + Debug + x64 + Release Win32 + + Release + x64 + @@ -25,12 +33,24 @@ false MultiByte + + StaticLibrary + v143 + false + MultiByte + StaticLibrary v143 false MultiByte + + StaticLibrary + v143 + false + MultiByte + @@ -38,22 +58,41 @@ + + + + + + + + $(SolutionDir)\build\output\$(Configuration)-$(Platform)\lib\ $(SolutionDir)\build\intermediate\$(Configuration)-$(Platform)\$(ProjectName)\ false + + $(SolutionDir)\build\output\$(Configuration)-$(Platform)\lib\ + $(SolutionDir)\build\intermediate\$(Configuration)-$(Platform)\$(ProjectName)\ + false + $(SolutionDir)\build\output\$(Configuration)-$(Platform)\lib\ $(SolutionDir)\build\intermediate\$(Configuration)-$(Platform)\$(ProjectName)\ true $(ProjectName)d + + $(SolutionDir)\build\output\$(Configuration)-$(Platform)\lib\ + $(SolutionDir)\build\intermediate\$(Configuration)-$(Platform)\$(ProjectName)\ + true + $(ProjectName)d + MultiThreadedDLL @@ -86,6 +125,38 @@ .\MissionEditorPackLib.def + + + MultiThreadedDLL + Default + true + false + MaxSpeed + true + Level3 + ..\3rdParty\xcc\misc;.\;%(AdditionalIncludeDirectories) + NDEBUG;EF;WIN32;_LIB;NO_XIF_SUPPORT;NO_FT_SUPPORT;NO_AVI_SUPPORT;XCC_MINIMAL_BUILD;%(PreprocessorDefinitions) + .\Release\ + .\Release\MissionEditorPackLib.pch + .\Release\ + .\Release\ + stdcpp20 + + + 0x0407 + NDEBUG;%(PreprocessorDefinitions) + + + true + .\Release\MissionEditorPackLib.bsc + + + true + + + .\MissionEditorPackLib.def + + MultiThreadedDebugDLL @@ -118,6 +189,38 @@ .\MissionEditorPackLib.def + + + MultiThreadedDebugDLL + Default + Disabled + true + Level3 + ProgramDatabase + ..\3rdParty\xcc\misc;.\;%(AdditionalIncludeDirectories) + .\Debug\ + .\Debug\MissionEditorPackLib.pch + .\Debug\ + .\Debug\ + EnableFastChecks + stdcpp20 + _DEBUG;WIN32;_LIB;NO_XIF_SUPPORT;NO_FT_SUPPORT;NO_AVI_SUPPORT;XCC_MINIMAL_BUILD;%(PreprocessorDefinitions) + + + 0x0407 + _DEBUG;%(PreprocessorDefinitions) + + + true + .\Debug\MissionEditorPackLib.bsc + + + true + + + .\MissionEditorPackLib.def + + diff --git a/MissionEditorPackLib/Vec3.h b/MissionEditorPackLib/Vec3.h index 5c46886..70a5969 100644 --- a/MissionEditorPackLib/Vec3.h +++ b/MissionEditorPackLib/Vec3.h @@ -50,7 +50,7 @@ public: inline T length() const { - return sqrt(squaredLength()); + return static_cast(sqrt(squaredLength())); } inline T squaredLength() const diff --git a/UnitTest/CIni_Test.cpp b/UnitTest/CIni_Test.cpp new file mode 100644 index 0000000..c22031b --- /dev/null +++ b/UnitTest/CIni_Test.cpp @@ -0,0 +1,240 @@ +#include "stdafx.h" +#include "../MissionEditor/IniFile.h" + +class IniTestHelper +{ + std::string m_fileName; + + void writeDownContent(const char* pContent) { + std::ofstream iniFile(m_fileName.c_str()); + ASSERT(iniFile.is_open() == true); + iniFile << pContent; + iniFile.flush(); + iniFile.close(); + } + + public : + IniTestHelper(std::string&& name, const char* pContent) : + m_fileName(std::move(name)) + { + ASSERT(!m_fileName.empty()); + ASSERT(pContent != nullptr); + writeDownContent(pContent); + } + ~IniTestHelper() { + remove(m_fileName.c_str()); + } + +}; + +TEST(CIniFileClass, LoadFileTest) { + auto const fileName = "test.ini"; + IniTestHelper helper(fileName, R"( +[Debug] +;DisplayAllOverlay=Yes ; Doesn´t cripple the overlay list in any way +;EnableTrackLogic=Yes ; Enables Track Logic +;IgnoreSHPImageHeadUnused=Yes ; Use this *carefully* to make SHP graphics of some mods work that incorrectly have the shadow flag set +AllowTunnels=yes +AllowUnidirectionalTunnels=yes + +[BuildingVoxelTurretsRA2OLD] +GTGCANX=00 +GTGCANY=44;-6 +)"); + + + CIniFile file; + ASSERT_EQ(file.LoadFile(std::string(fileName)), 0); + + EXPECT_NE(file.Size(), 0); + EXPECT_EQ(true, file.GetBool("Debug", "AllowTunnels")); + EXPECT_EQ(false, file.GetBool("Debug", "DisplayAllOverlay")); + EXPECT_EQ("00", file.GetString("BuildingVoxelTurretsRA2OLD", "GTGCANX")); +} + + +TEST(CIniFileClass, IniSequenceTest) { + auto const fileName = "test.ini"; + IniTestHelper helper(fileName, R"( +[SlopeSetPiecesDirections] +Count=10 +0=Right_1 +1=Left_1 +2=Top_1 +3=Bottom_1 +4=Right_2 +5=Left_2 +6=Left_2 +7=Bottom_2 +8=Top_2 +9=Top_2 +)"); + + CIniFile file; + ASSERT_EQ(file.LoadFile(std::string(fileName)), 0); + EXPECT_EQ(11, file["SlopeSetPiecesDirections"].Size()); + EXPECT_EQ("10", file["SlopeSetPiecesDirections"].Nth(0).second); + +} + +TEST(CIniFileClass, IniSetValueTest) { + auto const fileName = "test.ini"; + IniTestHelper helper(fileName, R"( +[Debug] +;DisplayAllOverlay=Yes ; Doesn´t cripple the overlay list in any way +;EnableTrackLogic=Yes ; Enables Track Logic +;IgnoreSHPImageHeadUnused=Yes ; Use this *carefully* to make SHP graphics of some mods work that incorrectly have the shadow flag set +AllowTunnels=yes +AllowUnidirectionalTunnels=yes +)"); + + CIniFile file; + ASSERT_EQ(file.LoadFile(std::string(fileName)), 0); + // Test value not exists + EXPECT_EQ(false, file.GetBool("Debug", "DisplayAllOverlay")); + file.SetBool("Debug", "DisplayAllOverlay", true); + EXPECT_EQ(true, file.GetBool("Debug", "DisplayAllOverlay")); + // Test existed value and override + EXPECT_EQ(true, file.GetBool("Debug", "AllowTunnels")); + file.SetBool("Debug", "AllowTunnels", false); + EXPECT_EQ(false, file.GetBool("Debug", "AllowTunnels")); + // Test section not exists + EXPECT_EQ("", file.GetString("SlopeSetPiecesDirections", "0")); + file.SetString("SlopeSetPiecesDirections", "0", "Right_1"); + EXPECT_EQ("Right_1", file.GetString("SlopeSetPiecesDirections", "0")); +} + +TEST(CIniFileClass, IniSetSectionTest) { + auto const fileName = "test.ini"; + IniTestHelper helper(fileName, R"( +[SlopeSetPiecesDirections] +Count=10 +0=Right_1 +1=Left_1 +2=Top_1 +3=Bottom_1 +4=Right_2 +5=Left_2 +6=Left_2 +7=Bottom_2 +8=Top_2 +9=Top_2 +)"); + + CIniFile file; + ASSERT_EQ(file.LoadFile(std::string(fileName)), 0); + + CIniFile anotherIni; + anotherIni.AddSection("Debug"); + auto pDebugSecAnother = anotherIni.TryGetSection("Debug"); + ASSERT_NE(pDebugSecAnother, nullptr); + pDebugSecAnother->SetBool("DisplayAllOverlay", false); + pDebugSecAnother->SetBool("AllowTunnels", true); + + + file.SetSection("Debug", anotherIni["Debug"]); + EXPECT_EQ(true, file.GetBool("Debug", "AllowTunnels")); + EXPECT_EQ(false, file.GetBool("Debug", "DisplayAllOverlay")); +} + +TEST(CIniFileClass, IniAddSectionTest) { + auto const fileName = "test.ini"; + IniTestHelper helper(fileName, R"( +[SlopeSetPiecesDirections] +Count=10 +0=Right_1 +1=Left_1 +2=Top_1 +3=Bottom_1 +4=Right_2 +5=Left_2 +6=Left_2 +7=Bottom_2 +8=Top_2 +9=Top_2 +)"); + + CIniFile file; + ASSERT_EQ(file.LoadFile(std::string(fileName)), 0); + file.AddSection("Debug"); + auto pDebugSec = file.TryGetSection("Debug"); + ASSERT_NE(pDebugSec, nullptr); + pDebugSec->SetBool("DisplayAllOverlay", false); + pDebugSec->SetBool("AllowTunnels", true); + EXPECT_EQ(true, file.GetBool("Debug", "AllowTunnels")); + EXPECT_EQ(false, file.GetBool("Debug", "DisplayAllOverlay")); +} + +TEST(CIniFileClass, IniDeleteSectionTest) { + auto const fileName = "test.ini"; + IniTestHelper helper(fileName, R"( +[LUNARLimits] +TreeMax=999 +TreeMin=999 + +[URBANLimits] +TreeMax=999 +;TreeMax=27 + +[TEMPERATELimits] +TreeMax=999 +;TreeMax=27 + +[SNOWLimits] +TreeMax=999 +;TreeMax=27 + +[NEWURBANLimits] +TreeMax=999 +;TreeMax=27 + +[DESERTLimits] +TreeMin=30 +TreeMax=999 +)"); + + CIniFile file; + ASSERT_EQ(file.LoadFile(std::string(fileName)), 0); + + EXPECT_EQ(999, file.GetInteger("SNOWLimits", "TreeMax")); + EXPECT_EQ(999, file.GetInteger("LUNARLimits", "TreeMin")); + + EXPECT_EQ(6, file.Size()); + file.DeleteSection("SNOWLimits"); + + EXPECT_EQ(0, file.GetInteger("SNOWLimits", "TreeMax")); + EXPECT_EQ(nullptr, file.TryGetSection("SNOWLimits")); + EXPECT_EQ(5, file.Size()); +} + +TEST(CIniFileClass, IniDeleteValueTest) { + auto const fileName = "test.ini"; + IniTestHelper helper(fileName, R"( +[LUNARLimits] +TreeMax=999 +TreeMin=999 + +[NewUrbanInfo] +Morphable2=114 +Ramps2=117 +Cliffs2=110 +CliffsWater2=112 + +; tileset ini overwritings +; only used by FinalAlert +[IgnoreSetTEMPERATE] +0=77 +1=78 +2=79 +)"); + + CIniFile file; + ASSERT_EQ(file.LoadFile(std::string(fileName)), 0); + + EXPECT_EQ(114, file.GetInteger("NewUrbanInfo", "Morphable2")); + file.RemoveValueByKey("NewUrbanInfo", "Morphable2"); + + EXPECT_EQ(0, file.GetInteger("NewUrbanInfo", "Morphable2")); + EXPECT_EQ(false, file["NewUrbanInfo"].Exists("Morphable2")); + +} \ No newline at end of file diff --git a/UnitTest/StdAfx.h b/UnitTest/StdAfx.h new file mode 100644 index 0000000..6addd5a --- /dev/null +++ b/UnitTest/StdAfx.h @@ -0,0 +1,32 @@ +/* + FinalSun/FinalAlert 2 Mission Editor + + Copyright (C) 1999-2024 Electronic Arts, Inc. + Authored by Matthias Wagner + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +// stdafx.h : include everything that should be available everywhere in the code +// + +#pragma once + +#include +#include +#include + +#if !defined(ASSERT) +#define ASSERT(x) if (!(x)) throw("assertion failed"); +#endif \ No newline at end of file diff --git a/UnitTest/UnitTest.cpp b/UnitTest/UnitTest.cpp new file mode 100644 index 0000000..13f2772 --- /dev/null +++ b/UnitTest/UnitTest.cpp @@ -0,0 +1,2 @@ +#include "stdafx.h" + diff --git a/UnitTest/UnitTest.vcxproj b/UnitTest/UnitTest.vcxproj new file mode 100644 index 0000000..76b6c5c --- /dev/null +++ b/UnitTest/UnitTest.vcxproj @@ -0,0 +1,146 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {75e18879-7564-4a2c-8c00-393a5a17171f} + UnitTest + 10.0 + + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + Application + true + v143 + MultiByte + + + Application + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;_AFXDLL;%(PreprocessorDefinitions) + true + $(SolutionDir)googletest\x64\include;%(AdditionalIncludeDirectories) + Create + MultiThreadedDebugDLL + stdcpp20 + + + Console + true + $(SolutionDir)googletest\x64\lib\$(Configuration)\*.lib;%(AdditionalDependencies) + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/UnitTest/UnitTest.vcxproj.filters b/UnitTest/UnitTest.vcxproj.filters new file mode 100644 index 0000000..37e3ea3 --- /dev/null +++ b/UnitTest/UnitTest.vcxproj.filters @@ -0,0 +1,36 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + 源文件 + + + 源文件 + + + 源文件 + + + + + 头文件 + + + 头文件 + + + \ No newline at end of file diff --git a/googletest b/googletest new file mode 160000 index 0000000..b0865c2 --- /dev/null +++ b/googletest @@ -0,0 +1 @@ +Subproject commit b0865c2800b6d2eda4d27b2ade82ee8302c788ea