1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-16 02:47:36 +02:00

Fixed a few potential crashes.

Minor improvements.
This commit is contained in:
Michał W. Urbańczyk 2010-07-07 02:29:07 +00:00
parent 74364865ff
commit d3c6270980
3 changed files with 55 additions and 36 deletions

View File

@ -5269,13 +5269,9 @@ void CTransformerWindow::addAll()
CTransformerWindow::CTransformerWindow(const CGHeroInstance * _hero, const CGTownInstance * _town):hero(_hero),town(_town)
{
OBJ_CONSTRUCTION_CAPTURING_ALL;
used = LCLICK;
pos.x = screen->w/2 - 300;
pos.y = screen->h/2 - 242;
bg = new CPicture ("SKTRNBK.PCX");
bg->colorizeAndConvert(LOCPLINT->playerID);
pos.w = bg->bg->w;
pos.h = bg->bg->h;
pos = center(bg->pos);
if (hero)
army = hero;
@ -5289,6 +5285,7 @@ CTransformerWindow::CTransformerWindow(const CGHeroInstance * _hero, const CGTow
all = new AdventureMapButton(CGI->generaltexth->zelp[590],boost::bind(&CTransformerWindow::addAll,this), 146,416,"ALTARMY.DEF",SDLK_a);
convert= new AdventureMapButton(CGI->generaltexth->zelp[591],boost::bind(&CTransformerWindow::makeDeal,this), 269,416,"ALTSACR.DEF",SDLK_RETURN);
cancel = new AdventureMapButton(CGI->generaltexth->zelp[592],boost::bind(&CGuiHandler::popIntTotally,&GH, this),392,416,"ICANCEL.DEF",SDLK_ESCAPE);
bar = new CGStatusBar(304, 469);
}
CTransformerWindow::~CTransformerWindow()

View File

@ -1005,6 +1005,7 @@ public:
std::vector<CItem*> items;
AdventureMapButton *all, *convert, *cancel;
CGStatusBar *bar;
void showAll(SDL_Surface * to);
void makeDeal();
void addAll();

View File

@ -925,6 +925,10 @@ void CGHeroInstance::initObj()
blockVisit = true;
speciality.growthsWithLevel = false;
Bonus bonus;
if(!type)
return; //TODO support prison
for (std::vector<specialInfo>::iterator it = type->spec.begin(); it != type->spec.end(); it++)
{
bonus.val = it->val;
@ -934,14 +938,27 @@ void CGHeroInstance::initObj()
switch (it->type)
{
case 1:// creature speciality
{
int creLevel = VLC->creh->creatures[it->val]->level;
if(!creLevel)
{
if(it->val == 146)
creLevel = 5; //treat ballista as 5-level
else
{
tlog2 << "Warning: unknown level of " << VLC->creh->creatures[it->val]->namePl << std::endl;
continue;
}
}
speciality.growthsWithLevel = true;
bonus.type = Bonus::SPECIAL_CREATURE;
bonus.valType = Bonus::ADDITIVE_VALUE;
bonus.subtype = 1; //attack
bonus.additionalInfo = level/VLC->creh->creatures[it->val]->level * VLC->creh->creatures[it->val]->attack;
bonus.additionalInfo = level/creLevel * VLC->creh->creatures[it->val]->attack;
speciality.bonuses.push_back (bonus);
bonus.subtype = 2; //defense
bonus.additionalInfo = level/VLC->creh->creatures[it->val]->level * VLC->creh->creatures[it->val]->defence;
bonus.additionalInfo = level/creLevel * VLC->creh->creatures[it->val]->defence;
speciality.bonuses.push_back (bonus);
bonus.subtype = 5;
bonus.additionalInfo = 1; //+1 speed
@ -960,6 +977,7 @@ void CGHeroInstance::initObj()
bonus.additionalInfo = 1; //+1 speed
speciality.bonuses.push_back (bonus);
}
}
break;
case 2://secondary skill
speciality.growthsWithLevel = true;
@ -2567,8 +2585,10 @@ const std::string & CGCreature::getHoverText() const
ms << std::pair<ui8,ui32>(6,pom) << " " << std::pair<ui8,ui32>(7,subID);
ms.toString(hoverName);
if(const CGHeroInstance *selHero = cb->getSelectedHero(cb->getCurrentPlayer()))
{
hoverName += "\n\n Threat: ";
float ratio = ((float)getArmyStrength() / cb->getSelectedHero(cb->getCurrentPlayer())->getTotalStrength());
float ratio = ((float)getArmyStrength() / selHero->getTotalStrength());
if (ratio < 0.1) hoverName += "Effortless";
else if (ratio < 0.25) hoverName += "Very Weak";
else if (ratio < 0.6) hoverName += "Weak";
@ -2581,6 +2601,7 @@ const std::string & CGCreature::getHoverText() const
else if (ratio < 8) hoverName += "Overpowering";
else if (ratio < 20) hoverName += "Deadly";
else hoverName += "Impossible";
}
return hoverName;
}
void CGCreature::onHeroVisit( const CGHeroInstance * h ) const