1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

lepsze przewijanie, wczytywanie większej ilosci tekstów

This commit is contained in:
mateuszb 2007-06-18 10:49:06 +00:00
parent 78ad4d39f0
commit bc7532e4dd
6 changed files with 359 additions and 18 deletions

View File

@ -201,6 +201,8 @@ void CArtHandler::loadArtifacts()
while(nart.desc2[nart.desc2.size()-1]!='"' ||
( (nart.name==std::string("£uk Penetracji")||nart.name==std::string("Bow of Seeking")) && bowCounter<4) ); //do - while end
//if(nart.name!=std::string("-1") && nart.name!=std::string("-2"))
nart.description += "\n\n";
nart.description += nart.desc2;
this->artifacts.push_back(nart);
delete[10000] read;
}

View File

@ -25,7 +25,10 @@ void CCreatureHandler::loadCreatures()
while(i<buf.size())
{
if(creatures.size()>190 && buf.substr(i, buf.size()-i).find('\r')==std::string::npos)
{
loadAnimationInfo();
break;
}
CCreature ncre;
@ -261,3 +264,181 @@ void CCreatureHandler::loadCreatures()
}
}
void CCreatureHandler::loadAnimationInfo()
{
std::ifstream inp("H3bitmap.lod\\CRANIM.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==2)
break;
}
i+=2;
for(int dd=0; dd<creatures.size(); ++dd)
{
loadUnitAnimInfo(creatures[dd], buf, i);
}
return;
}
void CCreatureHandler::loadUnitAnimInfo(CCreature & unit, std::string & src, int & i)
{
int befi=i;
for(i; i<src.size(); ++i)
{
if(src[i]=='\t')
break;
}
unit.timeBetweenFidgets = atof(src.substr(befi, i-befi).c_str());
++i;
while(unit.timeBetweenFidgets == 0.0)
{
for(i; i<src.size(); ++i)
{
if(src[i]=='\r')
break;
}
i+=2;
befi=i;
for(i; i<src.size(); ++i)
{
if(src[i]=='\t')
break;
}
unit.timeBetweenFidgets = atof(src.substr(befi, i-befi).c_str());
++i;
}
befi=i;
for(i; i<src.size(); ++i)
{
if(src[i]=='\t')
break;
}
unit.walkAnimationTime = atof(src.substr(befi, i-befi).c_str());
++i;
befi=i;
for(i; i<src.size(); ++i)
{
if(src[i]=='\t')
break;
}
unit.attackAnimationTime = atof(src.substr(befi, i-befi).c_str());
++i;
befi=i;
for(i; i<src.size(); ++i)
{
if(src[i]=='\t')
break;
}
unit.flightAnimationDistance = atof(src.substr(befi, i-befi).c_str());
++i;
///////////////////////
befi=i;
for(i; i<src.size(); ++i)
{
if(src[i]=='\t')
break;
}
unit.upperRightMissleOffsetX = atoi(src.substr(befi, i-befi).c_str());
++i;
befi=i;
for(i; i<src.size(); ++i)
{
if(src[i]=='\t')
break;
}
unit.upperRightMissleOffsetY = atoi(src.substr(befi, i-befi).c_str());
++i;
befi=i;
for(i; i<src.size(); ++i)
{
if(src[i]=='\t')
break;
}
unit.rightMissleOffsetX = atoi(src.substr(befi, i-befi).c_str());
++i;
befi=i;
for(i; i<src.size(); ++i)
{
if(src[i]=='\t')
break;
}
unit.rightMissleOffsetY = atoi(src.substr(befi, i-befi).c_str());
++i;
befi=i;
for(i; i<src.size(); ++i)
{
if(src[i]=='\t')
break;
}
unit.lowerRightMissleOffsetX = atoi(src.substr(befi, i-befi).c_str());
++i;
befi=i;
for(i; i<src.size(); ++i)
{
if(src[i]=='\t')
break;
}
unit.lowerRightMissleOffsetY = atoi(src.substr(befi, i-befi).c_str());
++i;
///////////////////////
for(int jjj=0; jjj<12; ++jjj)
{
befi=i;
for(i; i<src.size(); ++i)
{
if(src[i]=='\t')
break;
}
unit.missleFrameAngles[jjj] = atof(src.substr(befi, i-befi).c_str());
++i;
}
befi=i;
for(i; i<src.size(); ++i)
{
if(src[i]=='\t')
break;
}
unit.troopCountLocationOffset= atoi(src.substr(befi, i-befi).c_str());
++i;
befi=i;
for(i; i<src.size(); ++i)
{
if(src[i]=='\t')
break;
}
unit.attackClimaxFrame = atoi(src.substr(befi, i-befi).c_str());
++i;
for(i; i<src.size(); ++i)
{
if(src[i]=='\r')
break;
}
i+=2;
}

View File

@ -13,6 +13,15 @@ public:
std::string abilityText; //description of abilities
std::string abilityRefs; //references to abilities, in textformat
int idNumber;
///animation info
float timeBetweenFidgets, walkAnimationTime, attackAnimationTime, flightAnimationDistance;
int upperRightMissleOffsetX, rightMissleOffsetX, lowerRightMissleOffsetX, upperRightMissleOffsetY, rightMissleOffsetY, lowerRightMissleOffsetY;
float missleFrameAngles[12];
int troopCountLocationOffset, attackClimaxFrame;
///end of anim info
//TODO - zdolnoœci - na typie wyliczeniowym czy czymœ
};
@ -29,6 +38,8 @@ class CCreatureHandler
public:
std::vector<CCreature> creatures;
void loadCreatures();
void loadAnimationInfo();
void loadUnitAnimInfo(CCreature & unit, std::string & src, int & i);
};
#endif //CCREATUREHANDLER_H

View File

@ -185,3 +185,84 @@ void CHeroHandler::loadBiographies()
i+=2;
}
}
void CHeroHandler::loadHeroClasses()
{
std::ifstream inp("H3bitmap.lod\\HCTRAITS.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) //omitting rubbish
{
if(buf[i]=='\r')
++hmcr;
if(hmcr==2)
break;
}
i+=2;
for(int ss=0; ss<18; ++ss) //18 classes of hero (including conflux)
{
CHeroClass * hc = new CHeroClass;
int befi=i;
for(i; i<andame; ++i)
{
if(buf[i]=='\t')
break;
}
hc->name = buf.substr(befi, i-befi);
++i;
befi=i;
for(i; i<andame; ++i)
{
if(buf[i]=='\t')
break;
}
hc->aggression = atof(buf.substr(befi, i-befi).c_str());
++i;
befi=i;
for(i; i<andame; ++i)
{
if(buf[i]=='\t')
break;
}
hc->initialAttack = atoi(buf.substr(befi, i-befi).c_str());
++i;
befi=i;
for(i; i<andame; ++i)
{
if(buf[i]=='\t')
break;
}
hc->initialDefence = atoi(buf.substr(befi, i-befi).c_str());
++i;
befi=i;
for(i; i<andame; ++i)
{
if(buf[i]=='\t')
break;
}
hc->initialPower = atoi(buf.substr(befi, i-befi).c_str());
++i;
befi=i;
for(i; i<andame; ++i)
{
if(buf[i]=='\t')
break;
}
hc->initialKnowledge = atoi(buf.substr(befi, i-befi).c_str());
++i;
}
}

View File

@ -19,6 +19,20 @@ public:
bool operator<(CHero& drugi){if (ID < drugi.ID) return true; else return false;}
};
class CHeroClass
{
public:
std::string name;
float aggression;
int initialAttack, initialDefence, initialPower, initialKnowledge;
int proAttack[2]; //probability of gaining attack point on levels [0]: 2 - 9; [1]: 10+ (out of 100)
int proDefence[2]; //probability of gaining defence point on levels [0]: 2 - 9; [1]: 10+ (out of 100)
int proPower[2]; //probability of gaining power point on levels [0]: 2 - 9; [1]: 10+ (out of 100)
int proKnowledge[2]; //probability of gaining knowledge point on levels [0]: 2 - 9; [1]: 10+ (out of 100)
std::vector<int> proSec; //probabilities of gaining secondary skills (out of 112), in id order
int selectionProbability[9]; //probability of selection in towns
};
class CHeroInstance
{
public:
@ -32,9 +46,11 @@ class CHeroHandler
{
public:
nodrze<CHero> heroes;
std::vector<CHeroClass> heroClasses;
void loadHeroes();
void loadSpecialAbilities();
void loadBiographies();
void loadHeroClasses();
};

86
CMT.cpp
View File

@ -240,15 +240,15 @@ int _tmain(int argc, _TCHAR* argv[])
CArtHandler * arth = new CArtHandler;
arth->loadArtifacts();
cgi->arth = arth;
CHeroHandler * heroh = new CHeroHandler;
heroh->loadHeroes();
cgi->heroh = heroh;
CCreatureHandler * creh = new CCreatureHandler;
creh->loadCreatures();
cgi->creh = creh;
CAbilityHandler * abilh = new CAbilityHandler;
abilh->loadAbilities();
cgi->abilh = abilh;
CHeroHandler * heroh = new CHeroHandler;
heroh->loadHeroes();
cgi->heroh = heroh;
CSpellHandler * spellh = new CSpellHandler;
spellh->loadSpells();
cgi->spellh = spellh;
@ -281,6 +281,10 @@ int _tmain(int argc, _TCHAR* argv[])
//SDL_Surface * ss = ac->defs[0]->ourImages[0].bitmap;
//SDL_BlitSurface(ss, NULL, ekran, NULL);
bool scrollingLeft = false;
bool scrollingRight = false;
bool scrollingUp = false;
bool scrollingDown = false;
for(;;) // main loop
{
try
@ -295,26 +299,22 @@ int _tmain(int argc, _TCHAR* argv[])
{
case SDLK_LEFT:
{
if(xx>0)
xx--;
scrollingLeft = true;
break;
}
case (SDLK_RIGHT):
{
if(xx<ac->map.width-25)
xx++;
scrollingRight = true;
break;
}
case (SDLK_UP):
{
if(yy>0)
yy--;
scrollingUp = true;
break;
}
case (SDLK_DOWN):
{
if(yy<ac->map.height-18)
yy++;
scrollingDown = true;
break;
}
case (SDLK_q):
@ -332,18 +332,68 @@ int _tmain(int argc, _TCHAR* argv[])
break;
}
}
SDL_FillRect(ekran, NULL, SDL_MapRGB(ekran->format, 0, 0, 0));
SDL_Surface * help = mh->terrainRect(xx,yy,25,18,zz);
SDL_BlitSurface(help,NULL,ekran,NULL);
SDL_FreeSurface(help);
SDL_Flip(ekran);
}
} //keydown end
else if(sEvent.type==SDL_KEYUP)
{
switch (sEvent.key.keysym.sym)
{
case SDLK_LEFT:
{
scrollingLeft = false;
break;
}
case (SDLK_RIGHT):
{
scrollingRight = false;
break;
}
case (SDLK_UP):
{
scrollingUp = false;
break;
}
case (SDLK_DOWN):
{
scrollingDown = false;
break;
}
}
}//keyup end
} //event end
/////////////// scrolling terrain
if(scrollingLeft)
{
if(xx>0)
xx--;
}
if(scrollingRight)
{
if(xx<ac->map.width-25)
xx++;
}
if(scrollingUp)
{
if(yy>0)
yy--;
}
if(scrollingDown)
{
if(yy<ac->map.height-18)
yy++;
}
SDL_FillRect(ekran, NULL, SDL_MapRGB(ekran->format, 0, 0, 0));
SDL_Surface * help = mh->terrainRect(xx,yy,25,18,zz);
SDL_BlitSurface(help,NULL,ekran,NULL);
SDL_FreeSurface(help);
SDL_Flip(ekran);
/////////
}
catch(...)
{ continue; }
SDL_Delay(30); //give time for other apps
SDL_Delay(25); //give time for other apps
}
return 0;
}