1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-26 22:57:00 +02:00
vcmi/CPreGameTextHandler.cpp

422 lines
8.4 KiB
C++
Raw Normal View History

#include "stdafx.h"
#include "CPreGameTextHandler.h"
std::string CPreGameTextHandler::getTitle(std::string text)
{
std::string ret;
int i=0;
while ((text[i++]!='{'));
while ((text[i]!='}') && (i<text.length()))
ret+=text[i++];
return ret;
}
std::string CPreGameTextHandler::getDescr(std::string text)
{
std::string ret;
int i=0;
while ((text[i++]!='}'));
i+=2;
while ((text[i]!='"') && (i<text.length()))
ret+=text[i++];
return ret;
}
void CPreGameTextHandler::loadTexts()
{
std::ifstream inp("H3bitmap.lod\\ZELP.TXT", std::ios::in|std::ios::binary);
inp.seekg(0,std::ios::end); // na koniec
int andame = inp.tellg(); // read length
inp.seekg(0,std::ios::beg); // wracamy na poczatek
char * bufor = new char[andame]; // allocate memory
inp.read((char*)bufor, andame); // read map file to buffer
std::string buf = std::string(bufor);
delete [andame] bufor;
int i=0; //buf iterator
int hmcr=0;
for(i; i<andame; ++i)
{
if(buf[i]=='\r')
++hmcr;
if(hmcr==3)
break;
}
i+=3;
int befi=i;
for(i; i<andame; ++i)
{
if(buf[i]=='\t')
break;
}
mainNewGame = buf.substr(befi, i-befi);
++i;
hmcr = 0;
for(i; i<andame; ++i)
{
if(buf[i]=='\r')
++hmcr;
if(hmcr==1)
break;
}
i+=3;
befi=i;
for(i; i<andame; ++i)
{
if(buf[i]=='\t')
break;
}
mainLoadGame = buf.substr(befi, i-befi);
++i;
hmcr = 0;
for(i; i<andame; ++i)
{
if(buf[i]=='\r')
++hmcr;
if(hmcr==1)
break;
}
i+=3;
befi=i;
for(i; i<andame; ++i)
{
if(buf[i]=='\t')
break;
}
mainHighScores = buf.substr(befi, i-befi);
++i;
hmcr = 0;
for(i; i<andame; ++i)
{
if(buf[i]=='\r')
++hmcr;
if(hmcr==1)
break;
}
i+=3;
befi=i;
for(i; i<andame; ++i)
{
if(buf[i]=='\t')
break;
}
mainCredits = buf.substr(befi, i-befi);
++i;
hmcr = 0;
for(i; i<andame; ++i)
{
if(buf[i]=='\r')
++hmcr;
if(hmcr==1)
break;
}
i+=3;
befi=i;
for(i; i<andame; ++i)
{
if(buf[i]=='\t')
break;
}
mainQuit = buf.substr(befi, i-befi);
++i;
hmcr = 0;
for(i; i<andame; ++i)
{
if(buf[i]=='\r')
++hmcr;
if(hmcr==3)
break;
}
i+=3;
befi=i;
for(i; i<andame; ++i)
{
if(buf[i]=='\t')
break;
}
ngSingleScenario = buf.substr(befi, i-befi);
++i;
hmcr = 0;
for(i; i<andame; ++i)
{
if(buf[i]=='\r')
++hmcr;
if(hmcr==1)
break;
}
i+=3;
befi=i;
for(i; i<andame; ++i)
{
if(buf[i]=='\t')
break;
}
ngCampain = buf.substr(befi, i-befi);
++i;
hmcr = 0;
for(i; i<andame; ++i)
{
if(buf[i]=='\r')
++hmcr;
if(hmcr==1)
break;
}
i+=3;
befi=i;
for(i; i<andame; ++i)
{
if(buf[i]=='\t')
break;
}
ngMultiplayer = buf.substr(befi, i-befi);
++i;
hmcr = 0;
for(i; i<andame; ++i)
{
if(buf[i]=='\r')
++hmcr;
if(hmcr==1)
break;
}
i+=3;
befi=i;
for(i; i<andame; ++i)
{
if(buf[i]=='\t')
break;
}
ngTutorial = buf.substr(befi, i-befi);
++i;
hmcr = 0;
for(i; i<andame; ++i)
{
if(buf[i]=='\r')
++hmcr;
if(hmcr==1)
break;
}
i+=3;
befi=i;
for(i; i<andame; ++i)
{
if(buf[i]=='\t')
break;
}
ngBack = buf.substr(befi, i-befi);
++i;
hmcr = 0;
for(i; i<andame; ++i)
{
if(buf[i]=='\r')
++hmcr;
if(hmcr==4)
break;
}
i+=2;
loadToIt(singleChooseScenario, buf, i);
loadToIt(singleSetAdvOptions, buf, i);
loadToIt(singleRandomMap, buf, i);
loadToIt(singleScenarioName, buf, i);
loadToIt(singleDescriptionTitle, buf, i);
loadToIt(singleDescriptionText, buf, i);
loadToIt(singleEasy, buf, i);
loadToIt(singleNormal, buf, i);
loadToIt(singleHard, buf, i);
loadToIt(singleExpert, buf, i);
loadToIt(singleImpossible, buf, i);
loadToIt(singleAllyFlag[0], buf, i);
loadToIt(singleAllyFlag[1], buf, i);
loadToIt(singleAllyFlag[2], buf, i);
loadToIt(singleAllyFlag[3], buf, i, 1);
loadToIt(singleAllyFlag[4], buf, i, 1);
loadToIt(singleAllyFlag[5], buf, i, 1);
loadToIt(singleAllyFlag[6], buf, i, 1);
loadToIt(singleAllyFlag[7], buf, i, 1);
loadToIt(singleEnemyFlag[0], buf, i, 1);
loadToIt(singleEnemyFlag[1], buf, i, 1);
loadToIt(singleEnemyFlag[2], buf, i, 1);
loadToIt(singleEnemyFlag[3], buf, i, 1);
loadToIt(singleEnemyFlag[4], buf, i, 1);
loadToIt(singleEnemyFlag[5], buf, i, 1);
loadToIt(singleEnemyFlag[6], buf, i, 1);
loadToIt(singleEnemyFlag[7], buf, i, 1);
loadToIt(singleViewHideScenarioList, buf, i, 1);
loadToIt(singleViewHideAdvOptions, buf, i, 1);
loadToIt(singlePlayRandom, buf, i, 1);
loadToIt(singleChatDesc, buf, i, 1);
loadToIt(singleMapDifficulty, buf, i, 1);
loadToIt(singleRating, buf, i, 1);
loadToIt(singleMapPossibleDifficulties, buf, i, 1);
loadToIt(singleVicCon, buf, i, 1);
loadToIt(singleLossCon, buf, i, 1);
loadToIt(singleSFilter, buf, i, 1);
loadToIt(singleMFilter, buf, i, 1);
loadToIt(singleLFilter, buf, i, 1);
loadToIt(singleXLFilter, buf, i, 1);
loadToIt(singleAllFilter, buf, i, 1);
for(int vv=0; vv<18; ++vv)
{
loadToIt(singleScenarioNameNr[vv], buf, i, 1);
}
for(int vv=0; vv<18; ++vv)
{
loadToIt(singleEntryScenarioNameNr[vv], buf, i, 1);
}
std::string ff = singleEntryScenarioNameNr[4];
loadToIt(singleTurnDuration, buf, i, 1);
loadToIt(singleChatText, buf, i, 0);
loadToIt(singleChatEntry, buf, i, 0);
loadToIt(singleChatPlug, buf, i, 0);
loadToIt(singleChatPlayer, buf, i, 0);
loadToIt(singleChatPlayerSlider, buf, i, 0);
loadToIt(singleRollover, buf, i, 0);
loadToIt(singleNext, buf, i, 0);
loadToIt(singleBegin, buf, i, 0);
loadToIt(singleBack, buf, i, 0);
loadToIt(singleSSExit, buf, i, 0);
loadToIt(singleWhichMap, buf, i, 0);
loadToIt(singleSortNumber, buf, i, 0);
loadToIt(singleSortSize, buf, i, 0);
loadToIt(singleSortVersion, buf, i, 0);
loadToIt(singleSortAlpha, buf, i, 0);
loadToIt(singleSortVictory, buf, i, 0);
loadToIt(singleSortLoss, buf, i, 1);
loadToIt(singleBriefing, buf, i, 1);
loadToIt(singleSSHero, buf, i, 1);
loadToIt(singleGoldpic, buf, i, 1);
for(int vv=0; vv<8; ++vv)
{
loadToIt(singleHumanCPU[vv], buf, i, 1);
}
for(int vv=0; vv<8; ++vv)
{
loadToIt(singleHandicap[vv], buf, i, 1);
}
for(int vv=0; vv<8; ++vv)
{
loadToIt(singleTownLeft[vv], buf, i, 1);
}
for(int vv=0; vv<8; ++vv)
{
loadToIt(singleTownRite[vv], buf, i, 1);
}
for(int vv=0; vv<8; ++vv)
{
loadToIt(singleHeroLeft[vv], buf, i, 1);
}
for(int vv=0; vv<8; ++vv)
{
loadToIt(singleHeroRite[vv], buf, i, 1);
}
for(int vv=0; vv<8; ++vv)
{
loadToIt(singleResLeft[vv], buf, i, 1);
}
for(int vv=0; vv<8; ++vv)
{
loadToIt(singleResRite[vv], buf, i, 1);
}
for(int vv=0; vv<8; ++vv)
{
loadToIt(singleHeroSetting[vv], buf, i, 1);
}
for(int vv=0; vv<8; ++vv)
{
loadToIt(singleTownSetting[vv], buf, i, 1);
}
loadToIt(singleConstCreateMap, buf, i, 1);
loadToIt(singleConstMapSizeLabel, buf, i, 1);
loadToIt(singleConstSmallMap, buf, i, 1);
loadToIt(singleConstMediumMap, buf, i, 1);
loadToIt(singleConstLargeMap, buf, i, 1);
loadToIt(singleConstHugeMap, buf, i, 1);
loadToIt(singleConstMapLevels, buf, i, 1);
loadToIt(singleConstHumanPositionsLabel, buf, i, 1);
for(int vv=0; vv<8; ++vv)
{
loadToIt(singleConstNHumans[vv], buf, i, 1);
}
loadToIt(singleConstRandomHumans, buf, i, 1);
loadToIt(singleConstHumanTeamsLabel, buf, i, 1);
loadToIt(singleConstNoHumanTeams, buf, i, 1);
for(int vv=0; vv<7; ++vv)
{
loadToIt(singleConstNHumanTeams[vv], buf, i, 1);
}
}
void CPreGameTextHandler::loadToIt(std::string &dest, std::string &src, int &iter, int mode)
{
switch(mode)
{
case 0:
{
int hmcr = 0;
for(iter; iter<src.size(); ++iter)
{
if(src[iter]=='\t')
++hmcr;
if(hmcr==1)
break;
}
++iter;
int befi=iter;
for(iter; iter<src.size(); ++iter)
{
if(src[iter]=='\t')
break;
}
dest = src.substr(befi, iter-befi);
++iter;
hmcr = 0;
for(iter; iter<src.size(); ++iter)
{
if(src[iter]=='\r')
++hmcr;
if(hmcr==1)
break;
}
iter+=2;
break;
}
case 1:
{
int hmcr = 0;
for(iter; iter<src.size(); ++iter)
{
if(src[iter]=='\t')
++hmcr;
if(hmcr==1)
break;
}
++iter;
int befi=iter;
for(iter; iter<src.size(); ++iter)
{
if(src[iter]=='\r')
break;
}
dest = src.substr(befi, iter-befi);
iter+=2;
}
}
}