2011-12-14 00:23:17 +03:00
|
|
|
#include "StdInc.h"
|
2007-07-08 20:28:08 +03:00
|
|
|
#include "CGeneralTextHandler.h"
|
2011-12-14 00:23:17 +03:00
|
|
|
|
2012-08-01 15:02:54 +03:00
|
|
|
#include "Filesystem/CResourceLoader.h"
|
2012-08-25 11:44:51 +03:00
|
|
|
#include "Filesystem/CInputStream.h"
|
2011-12-14 00:23:17 +03:00
|
|
|
#include "GameConstants.h"
|
2007-07-08 20:28:08 +03:00
|
|
|
|
2012-08-25 11:44:51 +03:00
|
|
|
// #include <locale> //needed?
|
|
|
|
|
2009-04-15 17:03:31 +03:00
|
|
|
/*
|
|
|
|
* CGeneralTextHandler.cpp, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2012-08-25 11:44:51 +03:00
|
|
|
//Helper for string -> float conversion
|
|
|
|
class LocaleWithComma: public std::numpunct<char>
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
char do_decimal_point() const
|
|
|
|
{
|
|
|
|
return ',';
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
CLegacyConfigParser::CLegacyConfigParser(std::string URI)
|
2008-12-22 19:48:41 +02:00
|
|
|
{
|
2012-08-25 11:44:51 +03:00
|
|
|
init(CResourceHandler::get()->load(ResourceID(URI, EResType::TEXT)));
|
2008-12-22 19:48:41 +02:00
|
|
|
}
|
2009-07-03 22:57:14 +03:00
|
|
|
|
2012-08-25 11:44:51 +03:00
|
|
|
CLegacyConfigParser::CLegacyConfigParser(const std::unique_ptr<CInputStream> & input)
|
2009-07-03 22:57:14 +03:00
|
|
|
{
|
2012-08-25 11:44:51 +03:00
|
|
|
init(input);
|
2009-07-03 22:57:14 +03:00
|
|
|
}
|
|
|
|
|
2012-08-25 11:44:51 +03:00
|
|
|
void CLegacyConfigParser::init(const std::unique_ptr<CInputStream> & input)
|
2012-08-01 15:02:54 +03:00
|
|
|
{
|
2012-08-25 11:44:51 +03:00
|
|
|
data.reset(new char[input->getSize()]);
|
|
|
|
input->read((ui8*)data.get(), input->getSize());
|
2012-08-01 15:02:54 +03:00
|
|
|
|
2012-08-25 11:44:51 +03:00
|
|
|
curr = data.get();
|
|
|
|
end = curr + input->getSize();
|
2012-08-01 15:02:54 +03:00
|
|
|
}
|
|
|
|
|
2012-08-25 11:44:51 +03:00
|
|
|
std::string CLegacyConfigParser::extractQuotedPart()
|
2008-11-28 03:36:34 +02:00
|
|
|
{
|
2012-08-25 11:44:51 +03:00
|
|
|
assert(*curr == '\"');
|
2008-11-28 03:36:34 +02:00
|
|
|
|
2012-08-25 11:44:51 +03:00
|
|
|
curr++; // skip quote
|
|
|
|
char * begin = curr;
|
2008-11-28 03:36:34 +02:00
|
|
|
|
2012-08-25 11:44:51 +03:00
|
|
|
while (curr != end && *curr != '\"')
|
|
|
|
curr++;
|
2008-11-28 03:36:34 +02:00
|
|
|
|
2012-08-25 11:44:51 +03:00
|
|
|
return std::string(begin, curr++); //increment curr to close quote
|
|
|
|
}
|
2008-12-22 19:48:41 +02:00
|
|
|
|
2012-08-25 11:44:51 +03:00
|
|
|
std::string CLegacyConfigParser::extractQuotedString()
|
|
|
|
{
|
|
|
|
assert(*curr == '\"');
|
2008-12-22 19:48:41 +02:00
|
|
|
|
2012-08-25 11:44:51 +03:00
|
|
|
std::string ret;
|
|
|
|
while (true)
|
2008-12-22 19:48:41 +02:00
|
|
|
{
|
2012-08-25 11:44:51 +03:00
|
|
|
ret += extractQuotedPart();
|
2008-12-22 19:48:41 +02:00
|
|
|
|
2012-08-25 11:44:51 +03:00
|
|
|
if (curr < end && *curr == '\"') //double quote - add it to string and continue
|
|
|
|
ret += '\"';
|
|
|
|
else // end of string
|
|
|
|
return ret;
|
2008-12-22 19:48:41 +02:00
|
|
|
}
|
2012-08-25 11:44:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string CLegacyConfigParser::extractNormalString()
|
|
|
|
{
|
|
|
|
char * begin = curr;
|
|
|
|
|
|
|
|
while (curr < end && *curr != '\t' && *curr != '\r')//find end of string
|
|
|
|
curr++;
|
|
|
|
|
|
|
|
return std::string(begin, curr);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string CLegacyConfigParser::readString()
|
|
|
|
{
|
|
|
|
if (curr >= end || *curr == '\n')
|
|
|
|
return "";
|
|
|
|
|
|
|
|
std::string ret;
|
|
|
|
|
|
|
|
if (*curr == '\"')
|
|
|
|
ret = extractQuotedString();// quoted text - find closing quote
|
|
|
|
else
|
|
|
|
ret = extractNormalString();//string without quotes - copy till \t or \r
|
|
|
|
|
|
|
|
curr++;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
float CLegacyConfigParser::readNumber()
|
|
|
|
{
|
|
|
|
std::string input = readString();
|
|
|
|
|
|
|
|
std::istringstream stream(input);
|
|
|
|
|
|
|
|
if (input.find(',') != std::string::npos) // code to handle conversion with comma as decimal separator
|
|
|
|
stream.imbue(std::locale(std::locale(), new LocaleWithComma));
|
|
|
|
|
|
|
|
int result;
|
|
|
|
if ( !(stream >> result) )
|
|
|
|
return 0;
|
|
|
|
return result;
|
|
|
|
}
|
2008-12-22 19:48:41 +02:00
|
|
|
|
2012-08-25 11:44:51 +03:00
|
|
|
bool CLegacyConfigParser::isNextEntryEmpty()
|
|
|
|
{
|
2012-09-26 16:13:39 +03:00
|
|
|
char * nextSymbol = curr;
|
|
|
|
while (nextSymbol < end && *nextSymbol == ' ')
|
|
|
|
nextSymbol++; //find next meaningfull symbol
|
|
|
|
|
|
|
|
return nextSymbol >= end || *nextSymbol == '\n' || *nextSymbol == '\r' || *nextSymbol == '\t';
|
2012-08-25 11:44:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CLegacyConfigParser::endLine()
|
|
|
|
{
|
|
|
|
while (curr < end && *curr != '\n')
|
|
|
|
readString();
|
|
|
|
|
|
|
|
curr++;
|
|
|
|
|
|
|
|
return curr < end;
|
|
|
|
}
|
|
|
|
|
|
|
|
void readToVector(std::string sourceName, std::vector<std::string> & dest)
|
|
|
|
{
|
|
|
|
CLegacyConfigParser parser(sourceName);
|
|
|
|
do
|
2008-12-22 19:48:41 +02:00
|
|
|
{
|
2012-08-25 11:44:51 +03:00
|
|
|
dest.push_back(parser.readString());
|
2008-12-22 19:48:41 +02:00
|
|
|
}
|
2012-08-25 11:44:51 +03:00
|
|
|
while (parser.endLine());
|
|
|
|
}
|
2008-12-22 19:48:41 +02:00
|
|
|
|
2012-08-25 11:44:51 +03:00
|
|
|
void CGeneralTextHandler::load()
|
|
|
|
{
|
|
|
|
readToVector("DATA/VCDESC.TXT", victoryConditions);
|
|
|
|
readToVector("DATA/LCDESC.TXT", lossCondtions);
|
|
|
|
readToVector("DATA/TCOMMAND.TXT", tcommands);
|
|
|
|
readToVector("DATA/HALLINFO.TXT", hcommands);
|
|
|
|
readToVector("DATA/CASTINFO.TXT", fcommands);
|
|
|
|
readToVector("DATA/ADVEVENT.TXT", advobtxt);
|
|
|
|
readToVector("DATA/XTRAINFO.TXT", xtrainfo);
|
|
|
|
readToVector("DATA/RESTYPES.TXT", restypes);
|
|
|
|
readToVector("DATA/TERRNAME.TXT", terrainNames);
|
|
|
|
readToVector("DATA/RANDSIGN.TXT", randsign);
|
|
|
|
readToVector("DATA/ZCRGN1.TXT", creGens);
|
|
|
|
readToVector("DATA/CRGEN4.TXT", creGens4);
|
|
|
|
readToVector("DATA/OVERVIEW.TXT", overview);
|
|
|
|
readToVector("DATA/ARRAYTXT.TXT", arraytxt);
|
|
|
|
readToVector("DATA/PRISKILL.TXT", primarySkillNames);
|
|
|
|
readToVector("DATA/JKTEXT.TXT", jktexts);
|
|
|
|
readToVector("DATA/TVRNINFO.TXT", tavernInfo);
|
|
|
|
readToVector("DATA/TURNDUR.TXT", turnDurations);
|
|
|
|
readToVector("DATA/HEROSCRN.TXT", heroscrn);
|
|
|
|
readToVector("DATA/ARTEVENT.TXT", artifEvents);
|
|
|
|
readToVector("DATA/TENTCOLR.TXT", tentColors);
|
|
|
|
readToVector("DATA/SKILLLEV.TXT", levels);
|
|
|
|
readToVector("DATA/OBJNAMES.TXT", names);
|
|
|
|
|
|
|
|
{
|
|
|
|
CLegacyConfigParser parser("DATA/GENRLTXT.TXT");
|
|
|
|
parser.endLine();
|
|
|
|
do
|
2008-12-22 19:48:41 +02:00
|
|
|
{
|
2012-08-25 11:44:51 +03:00
|
|
|
allTexts.push_back(parser.readString());
|
2008-12-22 19:48:41 +02:00
|
|
|
}
|
2012-08-25 11:44:51 +03:00
|
|
|
while (parser.endLine());
|
2008-12-22 19:48:41 +02:00
|
|
|
}
|
2009-05-22 02:50:45 +03:00
|
|
|
{
|
2012-08-25 11:44:51 +03:00
|
|
|
CLegacyConfigParser parser("DATA/ZELP.TXT");
|
|
|
|
do
|
2009-05-22 02:50:45 +03:00
|
|
|
{
|
2012-08-25 11:44:51 +03:00
|
|
|
std::string first = parser.readString();
|
|
|
|
std::string second = parser.readString();
|
|
|
|
zelp.push_back(std::make_pair(first, second));
|
2009-05-22 02:50:45 +03:00
|
|
|
}
|
2012-08-25 11:44:51 +03:00
|
|
|
while (parser.endLine());
|
2009-05-22 02:50:45 +03:00
|
|
|
}
|
2008-12-22 19:48:41 +02:00
|
|
|
{
|
2012-08-25 11:44:51 +03:00
|
|
|
CLegacyConfigParser parser("DATA/HEROSPEC.TXT");
|
|
|
|
CLegacyConfigParser bioParser("DATA/HEROBIOS.TXT");
|
2008-12-22 19:48:41 +02:00
|
|
|
|
2012-08-25 11:44:51 +03:00
|
|
|
//skip header
|
|
|
|
parser.endLine();
|
|
|
|
parser.endLine();
|
2008-12-22 19:48:41 +02:00
|
|
|
|
2012-08-25 11:44:51 +03:00
|
|
|
do
|
|
|
|
{
|
|
|
|
HeroTexts texts;
|
|
|
|
texts.bonusName = parser.readString();
|
|
|
|
texts.shortBonus = parser.readString();
|
|
|
|
texts.longBonus = parser.readString();
|
|
|
|
texts.biography = bioParser.readString();
|
|
|
|
hTxts.push_back(texts);
|
|
|
|
}
|
|
|
|
while (parser.endLine() && bioParser.endLine());
|
2009-12-23 03:46:15 +02:00
|
|
|
}
|
2010-01-25 23:25:14 +02:00
|
|
|
{
|
2012-08-25 11:44:51 +03:00
|
|
|
CLegacyConfigParser nameParser("DATA/MINENAME.TXT");
|
|
|
|
CLegacyConfigParser eventParser("DATA/MINEEVNT.TXT");
|
2010-01-25 23:25:14 +02:00
|
|
|
|
2012-08-25 11:44:51 +03:00
|
|
|
do
|
|
|
|
{
|
|
|
|
std::string name = nameParser.readString();
|
|
|
|
std::string event = eventParser.readString();
|
|
|
|
mines.push_back(std::make_pair(name, event));
|
|
|
|
}
|
|
|
|
while (nameParser.endLine() && eventParser.endLine());
|
2010-02-01 19:07:46 +02:00
|
|
|
}
|
2009-01-11 00:08:18 +02:00
|
|
|
{
|
2012-08-25 11:44:51 +03:00
|
|
|
CLegacyConfigParser parser("DATA/PLCOLORS.TXT");
|
|
|
|
do
|
|
|
|
{
|
|
|
|
std::string color = parser.readString();
|
|
|
|
colors.push_back(color);
|
2009-01-11 00:08:18 +02:00
|
|
|
|
2012-08-25 11:44:51 +03:00
|
|
|
color[0] = toupper(color[0]);
|
|
|
|
capColors.push_back(color);
|
|
|
|
}
|
|
|
|
while (parser.endLine());
|
2009-01-11 00:08:18 +02:00
|
|
|
}
|
|
|
|
{
|
2012-08-25 11:44:51 +03:00
|
|
|
CLegacyConfigParser parser("DATA/SSTRAITS.TXT");
|
2009-01-11 00:08:18 +02:00
|
|
|
|
2012-08-25 11:44:51 +03:00
|
|
|
//skip header
|
|
|
|
parser.endLine();
|
|
|
|
parser.endLine();
|
2009-02-09 18:18:48 +02:00
|
|
|
|
2012-08-25 11:44:51 +03:00
|
|
|
do
|
|
|
|
{
|
|
|
|
skillName.push_back(parser.readString());
|
2009-02-09 18:18:48 +02:00
|
|
|
|
2012-08-25 11:44:51 +03:00
|
|
|
skillInfoTexts.push_back(std::vector<std::string>());
|
|
|
|
for(int j = 0; j < 3; j++)
|
|
|
|
skillInfoTexts.back().push_back(parser.readString());
|
|
|
|
}
|
|
|
|
while (parser.endLine());
|
2009-01-11 00:08:18 +02:00
|
|
|
}
|
|
|
|
{
|
2012-08-25 11:44:51 +03:00
|
|
|
CLegacyConfigParser parser("DATA/SEERHUT.TXT");
|
2009-01-11 00:08:18 +02:00
|
|
|
|
2012-08-25 11:44:51 +03:00
|
|
|
//skip header
|
|
|
|
parser.endLine();
|
2012-09-17 20:25:54 +03:00
|
|
|
parser.endLine();
|
2009-01-11 00:08:18 +02:00
|
|
|
|
2012-08-25 11:44:51 +03:00
|
|
|
for (int i = 0; i < 6; ++i)
|
|
|
|
seerEmpty.push_back(parser.readString());
|
2010-01-30 22:53:47 +02:00
|
|
|
|
2012-08-25 11:44:51 +03:00
|
|
|
quests.resize(10);
|
|
|
|
for (int i = 0; i < 9; ++i) //9 types of quests
|
2010-01-26 21:43:15 +02:00
|
|
|
{
|
2012-08-25 11:44:51 +03:00
|
|
|
quests[i].resize(5);
|
|
|
|
for (int j = 0; j < 5; ++j)
|
2010-01-26 21:43:15 +02:00
|
|
|
{
|
2012-08-25 11:44:51 +03:00
|
|
|
parser.readString(); //front description
|
|
|
|
for (int k = 0; k < 6; ++k)
|
|
|
|
quests[i][j].push_back(parser.readString());
|
|
|
|
|
|
|
|
parser.endLine();
|
2010-01-26 21:43:15 +02:00
|
|
|
}
|
|
|
|
}
|
2012-08-25 11:44:51 +03:00
|
|
|
quests[9].resize(1);
|
2010-01-30 22:53:47 +02:00
|
|
|
|
2012-08-25 11:44:51 +03:00
|
|
|
for (int k = 0; k < 6; ++k) //Time limit
|
|
|
|
{
|
|
|
|
quests[9][0].push_back(parser.readString());
|
|
|
|
}
|
|
|
|
parser.endLine();
|
|
|
|
|
|
|
|
parser.endLine(); // empty line
|
|
|
|
parser.endLine(); // header
|
|
|
|
|
|
|
|
for (int i = 0; i < 48; ++i)
|
|
|
|
{
|
|
|
|
seerNames.push_back(parser.readString());
|
|
|
|
parser.endLine();
|
|
|
|
}
|
2010-01-30 22:53:47 +02:00
|
|
|
}
|
2012-07-08 19:36:20 +03:00
|
|
|
{
|
2012-08-25 11:44:51 +03:00
|
|
|
CLegacyConfigParser parser("DATA/CAMPTEXT.TXT");
|
2012-07-08 19:36:20 +03:00
|
|
|
|
2012-08-25 11:44:51 +03:00
|
|
|
//skip header
|
|
|
|
parser.endLine();
|
|
|
|
|
|
|
|
std::string text;
|
|
|
|
do
|
2010-02-12 17:04:01 +02:00
|
|
|
{
|
2012-08-25 11:44:51 +03:00
|
|
|
text = parser.readString();
|
|
|
|
if (!text.empty())
|
2012-09-18 18:06:29 +03:00
|
|
|
campaignMapNames.push_back(text);
|
2010-02-12 17:04:01 +02:00
|
|
|
}
|
2012-08-25 11:44:51 +03:00
|
|
|
while (parser.endLine() && !text.empty());
|
2010-02-12 17:04:01 +02:00
|
|
|
|
2012-08-25 11:44:51 +03:00
|
|
|
for (size_t i=0; i<campaignMapNames.size(); i++)
|
2010-02-12 17:04:01 +02:00
|
|
|
{
|
2012-08-25 11:44:51 +03:00
|
|
|
do // skip empty space and header
|
2010-02-12 17:04:01 +02:00
|
|
|
{
|
2012-08-25 11:44:51 +03:00
|
|
|
text = parser.readString();
|
2010-02-12 17:04:01 +02:00
|
|
|
}
|
2012-08-25 11:44:51 +03:00
|
|
|
while (parser.endLine() && text.empty());
|
2011-02-07 16:39:17 +02:00
|
|
|
|
2012-08-25 11:44:51 +03:00
|
|
|
campaignRegionNames.push_back(std::vector<std::string>());
|
|
|
|
do
|
|
|
|
{
|
|
|
|
text = parser.readString();
|
|
|
|
if (!text.empty())
|
2012-09-18 18:06:29 +03:00
|
|
|
campaignRegionNames.back().push_back(text);
|
2012-08-25 11:44:51 +03:00
|
|
|
}
|
|
|
|
while (parser.endLine() && !text.empty());
|
|
|
|
}
|
|
|
|
}
|
2011-03-21 10:14:23 +02:00
|
|
|
{
|
2012-08-25 11:44:51 +03:00
|
|
|
CLegacyConfigParser parser("DATA/ZCREXP.TXT");
|
|
|
|
parser.endLine();//header
|
|
|
|
do
|
|
|
|
{
|
|
|
|
parser.readString(); //ignore 1st column with description
|
|
|
|
zcrexp.push_back(parser.readString());
|
|
|
|
}
|
|
|
|
while (parser.endLine());
|
2011-03-21 10:14:23 +02:00
|
|
|
}
|
|
|
|
|
2012-08-25 11:44:51 +03:00
|
|
|
std::string buffer;
|
2012-08-06 10:34:37 +03:00
|
|
|
std::ifstream ifs(CResourceHandler::get()->getResourceName(ResourceID("config/threatlevel.txt")), std::ios::binary);
|
2012-08-25 11:44:51 +03:00
|
|
|
getline(ifs, buffer); //skip 1st line
|
2011-02-07 16:39:17 +02:00
|
|
|
for (int i = 0; i < 13; ++i)
|
|
|
|
{
|
2012-08-25 11:44:51 +03:00
|
|
|
getline(ifs, buffer);
|
|
|
|
threat.push_back(buffer);
|
2011-02-07 16:39:17 +02:00
|
|
|
}
|
2009-01-11 00:08:18 +02:00
|
|
|
}
|
|
|
|
|
2010-02-12 17:04:01 +02:00
|
|
|
std::string CGeneralTextHandler::getTitle(const std::string & text)
|
2009-01-11 00:08:18 +02:00
|
|
|
{
|
|
|
|
std::string ret;
|
|
|
|
int i=0;
|
|
|
|
while ((text[i++]!='{'));
|
|
|
|
while ((text[i]!='}') && (i<text.length()))
|
|
|
|
ret+=text[i++];
|
|
|
|
return ret;
|
|
|
|
}
|
2010-02-12 17:04:01 +02:00
|
|
|
|
|
|
|
std::string CGeneralTextHandler::getDescr(const std::string & text)
|
2009-01-11 00:08:18 +02:00
|
|
|
{
|
|
|
|
std::string ret;
|
|
|
|
int i=0;
|
|
|
|
while ((text[i++]!='}'));
|
|
|
|
i+=2;
|
|
|
|
while ((text[i]!='"') && (i<text.length()))
|
|
|
|
ret+=text[i++];
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
CGeneralTextHandler::CGeneralTextHandler()
|
|
|
|
{
|
|
|
|
|
2009-10-22 05:09:14 +03:00
|
|
|
}
|