Browse Source

Don't load empty rumor strings

Ivan Savenko 3 years ago
parent
commit
10541855d9
2 changed files with 44 additions and 32 deletions
  1. 1 3
      lib/CGameState.cpp
  2. 43 29
      lib/CGeneralTextHandler.cpp

+ 1 - 3
lib/CGameState.cpp

@@ -2175,9 +2175,7 @@ void CGameState::updateRumor()
 
 		case RumorState::TYPE_RAND:
 			auto vector = VLC->generaltexth->findStringsWithPrefix("core.randtvrn");
-			do
-				rumorId = rand.nextInt((int)vector.size() - 1);
-			while(vector[rumorId].empty());
+			rumorId = rand.nextInt((int)vector.size() - 1);
 
 			break;
 		}

+ 43 - 29
lib/CGeneralTextHandler.cpp

@@ -398,7 +398,6 @@ CGeneralTextHandler::CGeneralTextHandler():
 	readToVector("core.priskill", "DATA/PRISKILL.TXT" );
 	readToVector("core.jktext",   "DATA/JKTEXT.TXT"   );
 	readToVector("core.tvrninfo", "DATA/TVRNINFO.TXT" );
-	readToVector("core.randtvrn", "DATA/RANDTVRN.TXT" );
 	readToVector("core.turndur",  "DATA/TURNDUR.TXT"  );
 	readToVector("core.heroscrn", "DATA/HEROSCRN.TXT" );
 	readToVector("core.tentcolr", "DATA/TENTCOLR.TXT" );
@@ -416,6 +415,21 @@ CGeneralTextHandler::CGeneralTextHandler():
 	for ( auto const & node : vcmiTexts.Struct())
 		registerString(node.first, node.second.String());
 
+	{
+		CLegacyConfigParser parser("DATA/RANDTVRN.TXT");
+		parser.endLine();
+		size_t index = 0;
+		do
+		{
+			std::string line = parser.readString();
+			if (!line.empty())
+			{
+				registerH3String("core.randtvrn", index, line);
+				index += 1;
+			}
+		}
+		while (parser.endLine());
+	}
 	{
 		CLegacyConfigParser parser("DATA/GENRLTXT.TXT");
 		parser.endLine();
@@ -543,12 +557,12 @@ CGeneralTextHandler::CGeneralTextHandler():
 	}
 	if (VLC->modh->modules.COMMANDERS)
 	{
-		if (CResourceHandler::get()->existsResource(ResourceID("DATA/ZNPC00.TXT", EResType::TEXT)))
-			readToVector("vcmi.znpc00", "DATA/ZNPC00.TXT" );
-	}
-}
-
-int32_t CGeneralTextHandler::pluralText(const int32_t textIndex, const int32_t count) const
+		if (CResourceHandler::get()->existsResource(ResourceID("DATA/ZNPC00.TXT", EResType::TEXT)))
+			readToVector("vcmi.znpc00", "DATA/ZNPC00.TXT" );
+	}
+}
+
+int32_t CGeneralTextHandler::pluralText(const int32_t textIndex, const int32_t count) const
 {
 	if(textIndex == 0)
 		return 0;
@@ -556,28 +570,28 @@ int32_t CGeneralTextHandler::pluralText(const int32_t textIndex, const int32_t c
 		return -textIndex;
 	else if(count == 1)
 		return textIndex;
-	else
-		return textIndex + 1;
-}
-
-void CGeneralTextHandler::dumpAllTexts()
-{
-	logGlobal->info("BEGIN TEXT EXPORT");
-	for ( auto const & entry : stringsLocalizations)
-	{
-		auto cleanString = entry.second;
-		boost::replace_all(cleanString, "\\", "\\\\");
-		boost::replace_all(cleanString, "\n", "\\n");
-		boost::replace_all(cleanString, "\r", "\\r");
-		boost::replace_all(cleanString, "\t", "\\t");
-		boost::replace_all(cleanString, "\"", "\\\"");
-
-		logGlobal->info("\"%s\" : \"%s\",", entry.first, cleanString);
-	}
-	logGlobal->info("END TEXT EXPORT");
-}
-
-size_t CGeneralTextHandler::getCampaignLength(size_t campaignID) const
+	else
+		return textIndex + 1;
+}
+
+void CGeneralTextHandler::dumpAllTexts()
+{
+	logGlobal->info("BEGIN TEXT EXPORT");
+	for ( auto const & entry : stringsLocalizations)
+	{
+		auto cleanString = entry.second;
+		boost::replace_all(cleanString, "\\", "\\\\");
+		boost::replace_all(cleanString, "\n", "\\n");
+		boost::replace_all(cleanString, "\r", "\\r");
+		boost::replace_all(cleanString, "\t", "\\t");
+		boost::replace_all(cleanString, "\"", "\\\"");
+
+		logGlobal->info("\"%s\" : \"%s\",", entry.first, cleanString);
+	}
+	logGlobal->info("END TEXT EXPORT");
+}
+
+size_t CGeneralTextHandler::getCampaignLength(size_t campaignID) const
 {
 	assert(campaignID < scenariosCountPerCampaign.size());