소스 검색

Fixed a few potential crashes.
Minor improvements.

Michał W. Urbańczyk 15 년 전
부모
커밋
d3c6270980
3개의 변경된 파일55개의 추가작업 그리고 36개의 파일을 삭제
  1. 2 5
      client/GUIClasses.cpp
  2. 1 0
      client/GUIClasses.h
  3. 52 31
      hch/CObjectHandler.cpp

+ 2 - 5
client/GUIClasses.cpp

@@ -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()

+ 1 - 0
client/GUIClasses.h

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

+ 52 - 31
hch/CObjectHandler.cpp

@@ -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,31 +938,45 @@ void CGHeroInstance::initObj()
 		switch (it->type)
 		{
 			case 1:// creature speciality
-				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;
-				speciality.bonuses.push_back (bonus);
-				bonus.subtype = 2; //defense
-				bonus.additionalInfo = level/VLC->creh->creatures[it->val]->level * VLC->creh->creatures[it->val]->defence;
-				speciality.bonuses.push_back (bonus);
-				bonus.subtype = 5;
-				bonus.additionalInfo = 1; //+1 speed
-				speciality.bonuses.push_back (bonus);
-				for (std::set<ui32>::iterator i = VLC->creh->creatures[it->val]->upgrades.begin();
-					i != VLC->creh->creatures[it->val]->upgrades.end(); i++)
 				{
-					bonus.val = *i; // for all direct upgrades of that creature
+					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[*i]->level * VLC->creh->creatures[*i]->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[*i]->level * VLC->creh->creatures[*i]->defence;
+					bonus.additionalInfo = level/creLevel * VLC->creh->creatures[it->val]->defence;
 					speciality.bonuses.push_back (bonus);
 					bonus.subtype = 5;
 					bonus.additionalInfo = 1; //+1 speed
 					speciality.bonuses.push_back (bonus);
+					for (std::set<ui32>::iterator i = VLC->creh->creatures[it->val]->upgrades.begin();
+						i != VLC->creh->creatures[it->val]->upgrades.end(); i++)
+					{
+						bonus.val = *i; // for all direct upgrades of that creature
+						bonus.subtype = 1; //attack
+						bonus.additionalInfo = level/VLC->creh->creatures[*i]->level * VLC->creh->creatures[*i]->attack;
+						speciality.bonuses.push_back (bonus);
+						bonus.subtype = 2; //defense
+						bonus.additionalInfo = level/VLC->creh->creatures[*i]->level * VLC->creh->creatures[*i]->defence;
+						speciality.bonuses.push_back (bonus);
+						bonus.subtype = 5;
+						bonus.additionalInfo = 1; //+1 speed
+						speciality.bonuses.push_back (bonus);
+					}
 				}
 				break;
 			case 2://secondary skill
@@ -2567,20 +2585,23 @@ const std::string & CGCreature::getHoverText() const
 	ms << std::pair<ui8,ui32>(6,pom) << " " << std::pair<ui8,ui32>(7,subID);
 	ms.toString(hoverName);
 
-	hoverName += "\n\n Threat: ";
-	float ratio = ((float)getArmyStrength() / cb->getSelectedHero(cb->getCurrentPlayer())->getTotalStrength());
-	if (ratio < 0.1) hoverName += "Effortless";
-	else if (ratio < 0.25) hoverName += "Very Weak";
-	else if (ratio < 0.6) hoverName += "Weak";
-	else if (ratio < 0.9) hoverName += "A bit weaker";
-	else if (ratio < 1.1) hoverName += "Equal";
-	else if (ratio < 1.3) hoverName += "A bit stronger";
-	else if (ratio < 1.8) hoverName += "Strong";
-	else if (ratio < 2.5) hoverName += "Very Strong";
-	else if (ratio < 4) hoverName += "Challenging";
-	else if (ratio < 8) hoverName += "Overpowering";
-	else if (ratio < 20) hoverName += "Deadly";
-	else hoverName += "Impossible";
+	if(const CGHeroInstance *selHero = cb->getSelectedHero(cb->getCurrentPlayer()))
+	{
+		hoverName += "\n\n Threat: ";
+		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";
+		else if (ratio < 0.9) hoverName += "A bit weaker";
+		else if (ratio < 1.1) hoverName += "Equal";
+		else if (ratio < 1.3) hoverName += "A bit stronger";
+		else if (ratio < 1.8) hoverName += "Strong";
+		else if (ratio < 2.5) hoverName += "Very Strong";
+		else if (ratio < 4) hoverName += "Challenging";
+		else if (ratio < 8) hoverName += "Overpowering";
+		else if (ratio < 20) hoverName += "Deadly";
+		else hoverName += "Impossible";
+	}
 	return hoverName;
 }
 void CGCreature::onHeroVisit( const CGHeroInstance * h ) const