瀏覽代碼

CBonusTypeHandler small refactoring

alexvins 11 年之前
父節點
當前提交
f837afdc47
共有 1 個文件被更改,包括 8 次插入16 次删除
  1. 8 16
      lib/CBonusTypeHandler.cpp

+ 8 - 16
lib/CBonusTypeHandler.cpp

@@ -13,7 +13,7 @@
 #include "JsonNode.h"
 #include "filesystem/Filesystem.h"
 
-#include "VCMI_Lib.h"
+#include "GameConstants.h"
 #include "CCreatureHandler.h"
 #include "CSpellHandler.h"
 
@@ -136,11 +136,13 @@ std::string CBonusTypeHandler::bonusToString(const Bonus *bonus, const IBonusBea
 		}
 		else if (name == "subtype.creature")
 		{
-			return VLC->creh->creatures[bonus->subtype]->namePl;
+			const CreatureID cre(bonus->subtype);
+			return cre.toCreature()->namePl;
 		}
 		else if (name == "subtype.spell")
 		{
-			 return VLC->spellh->spells[bonus->subtype]->name;
+			const SpellID sp(bonus->subtype);
+			return sp.toSpell()->name;
 		}		
 		else if (name == "MR")
 		{
@@ -153,20 +155,10 @@ std::string CBonusTypeHandler::bonusToString(const Bonus *bonus, const IBonusBea
 		}
 	};
 	
-	const CBonusType& bt = bonusTypes[bonus->type];
+	const CBonusType& bt = bonusTypes[bonus->type];	
+	const MacroString& macro = description ? bt.description : bt.name;
 	
-	std::string text;
-	
-	if (description)
-	{
-		text = bt.description.build(getValue);
-	}
-	else
-	{
-		text = bt.name.build(getValue);
-	}
-	
-	return text;	
+	return macro.build(getValue);	
 }
 
 std::string CBonusTypeHandler::bonusToGraphics(const Bonus* bonus) const