about summary refs log tree commit diff
diff options
context:
space:
mode:
authoroy <Tom_Adams@web.de>2012-02-05 15:53:22 +0100
committeroy <Tom_Adams@web.de>2012-02-05 15:53:22 +0100
commitc045071b40a635e3178ba8d55369eb01ba13102e (patch)
treed3622e7fb3438c5d88e92d5a3cae2bf26f54b858
parent27daa26b991d3fc92609a915f23eadbbd68cd9e9 (diff)
downloadzcatch-c045071b40a635e3178ba8d55369eb01ba13102e.tar.gz
zcatch-c045071b40a635e3178ba8d55369eb01ba13102e.zip
always show default country flag on invalid country index
-rw-r--r--src/game/client/components/countryflags.cpp23
1 files changed, 19 insertions, 4 deletions
diff --git a/src/game/client/components/countryflags.cpp b/src/game/client/components/countryflags.cpp
index e62f4e51..b63b126f 100644
--- a/src/game/client/components/countryflags.cpp
+++ b/src/game/client/components/countryflags.cpp
@@ -87,13 +87,28 @@ void CCountryFlags::LoadCountryflagsIndexfile()
 			str_format(aBuf, sizeof(aBuf), "loaded country flag '%s'", aOrigin);
 			Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "countryflags", aBuf);
 		}
-		m_aCountryFlags.add(CountryFlag);
+		m_aCountryFlags.add_unsorted(CountryFlag);
 	}
 	io_close(File);
+	m_aCountryFlags.sort_range();
 
-	mem_zero(m_CodeIndexLUT, sizeof(m_CodeIndexLUT));
+	// find index of default item
+	int DefaultIndex = 0, Index = 0;
+	for(sorted_array<CCountryFlag>::range r = m_aCountryFlags.all(); !r.empty(); r.pop_front(), ++Index)
+		if(r.front().m_CountryCode == -1)
+		{
+			DefaultIndex = Index;
+			break;
+		}
+	
+	// init LUT
+	if(DefaultIndex != 0)
+		for(int i = 0; i < CODE_RANGE; ++i)
+			m_CodeIndexLUT[i] = DefaultIndex;
+	else
+		mem_zero(m_CodeIndexLUT, sizeof(m_CodeIndexLUT));
 	for(int i = 0; i < m_aCountryFlags.size(); ++i)
-		m_CodeIndexLUT[max(0, (m_aCountryFlags[i].m_CountryCode-CODE_LB)%CODE_RANGE)] = i+1;
+		m_CodeIndexLUT[max(0, (m_aCountryFlags[i].m_CountryCode-CODE_LB)%CODE_RANGE)] = i;
 }
 
 void CCountryFlags::OnInit()
@@ -119,7 +134,7 @@ int CCountryFlags::Num() const
 
 const CCountryFlags::CCountryFlag *CCountryFlags::GetByCountryCode(int CountryCode) const
 {
-	return GetByIndex(m_CodeIndexLUT[max(0, (CountryCode-CODE_LB)%CODE_RANGE)]-1);
+	return GetByIndex(m_CodeIndexLUT[max(0, (CountryCode-CODE_LB)%CODE_RANGE)]);
 }
 
 const CCountryFlags::CCountryFlag *CCountryFlags::GetByIndex(int Index) const