1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-07-17 01:32:21 +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) CTransformerWindow::CTransformerWindow(const CGHeroInstance * _hero, const CGTownInstance * _town):hero(_hero),town(_town)
{ {
OBJ_CONSTRUCTION_CAPTURING_ALL; OBJ_CONSTRUCTION_CAPTURING_ALL;
used = LCLICK;
pos.x = screen->w/2 - 300;
pos.y = screen->h/2 - 242;
bg = new CPicture ("SKTRNBK.PCX"); bg = new CPicture ("SKTRNBK.PCX");
bg->colorizeAndConvert(LOCPLINT->playerID); bg->colorizeAndConvert(LOCPLINT->playerID);
pos.w = bg->bg->w; pos = center(bg->pos);
pos.h = bg->bg->h;
if (hero) if (hero)
army = 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); 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); 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); 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() CTransformerWindow::~CTransformerWindow()

View File

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

View File

@ -925,6 +925,10 @@ void CGHeroInstance::initObj()
blockVisit = true; blockVisit = true;
speciality.growthsWithLevel = false; speciality.growthsWithLevel = false;
Bonus bonus; Bonus bonus;
if(!type)
return; //TODO support prison
for (std::vector<specialInfo>::iterator it = type->spec.begin(); it != type->spec.end(); it++) for (std::vector<specialInfo>::iterator it = type->spec.begin(); it != type->spec.end(); it++)
{ {
bonus.val = it->val; bonus.val = it->val;
@ -934,14 +938,27 @@ void CGHeroInstance::initObj()
switch (it->type) switch (it->type)
{ {
case 1:// creature speciality 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; speciality.growthsWithLevel = true;
bonus.type = Bonus::SPECIAL_CREATURE; bonus.type = Bonus::SPECIAL_CREATURE;
bonus.valType = Bonus::ADDITIVE_VALUE; bonus.valType = Bonus::ADDITIVE_VALUE;
bonus.subtype = 1; //attack 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); speciality.bonuses.push_back (bonus);
bonus.subtype = 2; //defense 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); speciality.bonuses.push_back (bonus);
bonus.subtype = 5; bonus.subtype = 5;
bonus.additionalInfo = 1; //+1 speed bonus.additionalInfo = 1; //+1 speed
@ -960,6 +977,7 @@ void CGHeroInstance::initObj()
bonus.additionalInfo = 1; //+1 speed bonus.additionalInfo = 1; //+1 speed
speciality.bonuses.push_back (bonus); speciality.bonuses.push_back (bonus);
} }
}
break; break;
case 2://secondary skill case 2://secondary skill
speciality.growthsWithLevel = true; 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 << std::pair<ui8,ui32>(6,pom) << " " << std::pair<ui8,ui32>(7,subID);
ms.toString(hoverName); ms.toString(hoverName);
if(const CGHeroInstance *selHero = cb->getSelectedHero(cb->getCurrentPlayer()))
{
hoverName += "\n\n Threat: "; 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"; if (ratio < 0.1) hoverName += "Effortless";
else if (ratio < 0.25) hoverName += "Very Weak"; else if (ratio < 0.25) hoverName += "Very Weak";
else if (ratio < 0.6) hoverName += "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 < 8) hoverName += "Overpowering";
else if (ratio < 20) hoverName += "Deadly"; else if (ratio < 20) hoverName += "Deadly";
else hoverName += "Impossible"; else hoverName += "Impossible";
}
return hoverName; return hoverName;
} }
void CGCreature::onHeroVisit( const CGHeroInstance * h ) const void CGCreature::onHeroVisit( const CGHeroInstance * h ) const