Browse Source

Merge branch 'develop' into SpellsRefactoring4

Conflicts:
	lib/CSpellHandler.cpp
AlexVinS 11 years ago
parent
commit
752965ff69

+ 2 - 2
client/CPreGame.cpp

@@ -1240,7 +1240,7 @@ SelectionTab::SelectionTab(CMenuScreen::EState Type, const std::function<void(CM
 			if(tabType == CMenuScreen::saveGame)
 			{
 				txt = new CTextInput(Rect(32, 539, 350, 20), Point(-32, -25), "GSSTRIP.bmp", 0);
-				txt->filters.add(CTextInput::filenameFilter);
+				txt->filters += CTextInput::filenameFilter;
 			}
 			break;
 
@@ -4236,7 +4236,7 @@ CSimpleJoinScreen::CSimpleJoinScreen()
 
 	port = new CTextInput(Rect(25, 115, 175, 16), *bg);
     port->cb += std::bind(&CSimpleJoinScreen::onChange, this, _1);
-    port->filters.add(std::bind(&CTextInput::numberFilter, _1, _2, 0, 65535));
+    port->filters += std::bind(&CTextInput::numberFilter, _1, _2, 0, 65535);
 
 	ok     = new CButton(Point( 26, 142), "MUBCHCK.DEF", CGI->generaltexth->zelp[560], std::bind(&CSimpleJoinScreen::enterSelectionScreen, this), SDLK_RETURN);
 	cancel = new CButton(Point(142, 142), "MUBCANC.DEF", CGI->generaltexth->zelp[561], std::bind(&CGuiHandler::popIntTotally, std::ref(GH), this), SDLK_ESCAPE);

+ 1 - 0
client/battle/CBattleInterface.cpp

@@ -1544,6 +1544,7 @@ void CBattleInterface::castThisSpell(int spellID)
 	ba->side = defendingHeroInstance ? (curInt->playerID == defendingHeroInstance->tempOwner) : false;
 	spellToCast = ba;
 	spellDestSelectMode = true;
+	creatureCasting = false;
 
 	//choosing possible tragets
 	const CGHeroInstance * castingHero = (attackingHeroInstance->tempOwner == curInt->playerID) ? attackingHeroInstance : defendingHeroInstance;

+ 2 - 2
client/widgets/Buttons.cpp

@@ -150,7 +150,7 @@ void CButton::block(bool on)
 void CButton::onButtonClicked()
 {
 	// debug logging to figure out pressed button (and as result - player actions) in case of crash
-	logAnim->traceStream() << "Button clicked at " << pos.x << "x" << pos.y << ", " << callback.funcs.size() << " functions";
+	logAnim->traceStream() << "Button clicked at " << pos.x << "x" << pos.y;
 	CIntObject * parent = this->parent;
 	std::string prefix = "Parent is";
 	while (parent)
@@ -352,7 +352,7 @@ bool CToggleBase::canActivate()
 
 void CToggleBase::addCallback(std::function<void(bool)> function)
 {
-	callback.add(function);
+	callback += function;
 }
 
 CToggleButton::CToggleButton(Point position, const std::string &defName, const std::pair<std::string, std::string> &help,

+ 2 - 7
client/windows/CHeroWindow.cpp

@@ -295,13 +295,8 @@ void CHeroWindow::update(const CGHeroInstance * hero, bool redrawNeeded /*= fals
 
 void CHeroWindow::dismissCurrent()
 {
-	CFunctionList<void()> ony = std::bind(&CHeroWindow::close,this);
-	//ony += std::bind(&CCallback::dismissHero, LOCPLINT->cb.get(), curHero); //can't assign bool function to void function list :(
-	auto dismiss = [=]() -> void
-	{
-		LOCPLINT->cb.get()->dismissHero(curHero);
-	};
-	ony += dismiss;
+	CFunctionList<void()> ony = [=] { close(); };
+	ony += [=] { LOCPLINT->cb->dismissHero(curHero); };
 	LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[22], ony, 0, false);
 }
 

+ 2 - 2
client/windows/GUIClasses.cpp

@@ -382,8 +382,8 @@ CSplitWindow::CSplitWindow(const CCreature * creature, std::function<void(int, i
 	rightInput = new CTextInput(Rect(176, 218, 100, 36), FONT_BIG, std::bind(&CSplitWindow::setAmountText, this, _1, false));
 
 	//add filters to allow only number input
-	leftInput->filters.add(std::bind(&CTextInput::numberFilter, _1, _2, leftMin, leftMax));
-	rightInput->filters.add(std::bind(&CTextInput::numberFilter, _1, _2, rightMin, rightMax));
+	leftInput->filters += std::bind(&CTextInput::numberFilter, _1, _2, leftMin, leftMax);
+	rightInput->filters += std::bind(&CTextInput::numberFilter, _1, _2, rightMin, rightMax);
 
 	leftInput->setText(boost::lexical_cast<std::string>(leftAmount), false);
 	rightInput->setText(boost::lexical_cast<std::string>(rightAmount), false);

+ 3 - 4
client/windows/InfoWindows.cpp

@@ -202,10 +202,9 @@ void CInfoWindow::showYesNoDialog(const std::string & text, const std::vector<CC
 	pom.push_back(std::pair<std::string,CFunctionList<void()> >("IOKAY.DEF",0));
 	pom.push_back(std::pair<std::string,CFunctionList<void()> >("ICANCEL.DEF",0));
 	CInfoWindow * temp = new CInfoWindow(text, player, components ? *components : std::vector<CComponent*>(), pom, DelComps);
-	for(auto & elem : onYes.funcs)
-		temp->buttons[0]->addCallback(elem);
-	for(auto & elem : onNo.funcs)
-		temp->buttons[1]->addCallback(elem);
+
+	temp->buttons[0]->addCallback( onYes );
+	temp->buttons[1]->addCallback( onNo );
 
 	GH.pushInt(temp);
 }

+ 1 - 1
config/spells/other.json

@@ -208,7 +208,7 @@
 		"levels" : {
 			"base":{
 				"range" : "0",
-				"targetModifier":{"smart":false}
+				"targetModifier":{"smart":true}
 			}
 		},
 		"immunity" : {

+ 2 - 2
launcher/jsonutils.cpp

@@ -84,9 +84,9 @@ JsonNode toJson(QVariant object)
 		ret.Struct() = VariantToMap(object.toMap());
 	else if (object.canConvert<QVariantList>())
 		ret.Vector() = VariantToList(object.toList());
-	else if (object.type() == QMetaType::QString)
+	else if (static_cast<QMetaType::Type>(object.type()) == QMetaType::QString)
 		ret.String() = object.toString().toUtf8().data();
-	else if (object.type() == QMetaType::Bool)
+	else if (static_cast<QMetaType::Type>(object.type()) == QMetaType::Bool)
 		ret.Bool() = object.toBool();
 	else if (object.canConvert<double>())
 		ret.Float() = object.toFloat();

+ 15 - 8
lib/CSpellHandler.cpp

@@ -711,7 +711,7 @@ CSpell * CSpellHandler::loadFromJson(const JsonNode& json)
 		});
 	}
 
-	const std::string targetType = json["targetType"].String();
+	auto targetType = json["targetType"].String();
 
 	if(targetType == "NO_TARGET")
 		spell->targetType = CSpell::NO_TARGET;
@@ -724,6 +724,7 @@ CSpell * CSpellHandler::loadFromJson(const JsonNode& json)
 	else 
 		logGlobal->warnStream() << "Spell " << spell->name << ". Target type " << (targetType.empty() ? "empty" : "unknown ("+targetType+")") << ". Assumed NO_TARGET.";
 
+
 	spell->mainEffectAnim = json["anim"].Float();
 
 	for(const auto & counteredSpell: json["counters"].Struct())
@@ -769,12 +770,12 @@ CSpell * CSpellHandler::loadFromJson(const JsonNode& json)
 	else if(!implicitPositiveness)
 	{
 		spell->positiveness = CSpell::NEUTRAL; //duplicates constructor but, just in case
-		logGlobal->warnStream() << "Spell " << spell->name << ": no positiveness specified, assumed NEUTRAL";
+		logGlobal->errorStream() << "No positiveness specified, assumed NEUTRAL";
 	}
 
 	spell->isSpecial = flags["special"].Bool();
 
-	auto findBonus = [&](const std::string & name, std::vector<Bonus::BonusType> &vec)
+	auto findBonus = [&](std::string name, std::vector<Bonus::BonusType> &vec)
 	{
 		auto it = bonusNameMap.find(name);
 		if(it == bonusNameMap.end())
@@ -787,7 +788,7 @@ CSpell * CSpellHandler::loadFromJson(const JsonNode& json)
 		}
 	};
 
-	auto readBonusStruct = [&](const std::string & name, std::vector<Bonus::BonusType> &vec)
+	auto readBonusStruct = [&](std::string name, std::vector<Bonus::BonusType> &vec)
 	{
 		for(auto bonusData: json[name].Struct())
 		{
@@ -804,19 +805,24 @@ CSpell * CSpellHandler::loadFromJson(const JsonNode& json)
 	readBonusStruct("limit", spell->limiters);	
 	readBonusStruct("absoluteLimit", spell->absoluteLimiters);
 
+
 	const JsonNode & graphicsNode = json["graphics"];
 
-	spell->iconImmune =        graphicsNode["iconImmune"].String();
-	spell->iconBook =          graphicsNode["iconBook"].String();
-	spell->iconEffect =        graphicsNode["iconEffect"].String();
+	spell->iconImmune = graphicsNode["iconImmune"].String();
+	spell->iconBook = graphicsNode["iconBook"].String();
+	spell->iconEffect = graphicsNode["iconEffect"].String();
 	spell->iconScenarioBonus = graphicsNode["iconScenarioBonus"].String();
-	spell->iconScroll =        graphicsNode["iconScroll"].String();
+	spell->iconScroll = graphicsNode["iconScroll"].String();
+
+
 
 	const JsonNode & soundsNode = json["sounds"];
 
 	spell->castSound = soundsNode["cast"].String();
 
+
 	//load level attributes
+
 	const int levelsCount = GameConstants::SPELL_SCHOOL_LEVELS;
 
 	for(int levelIndex = 0; levelIndex < levelsCount; levelIndex++)
@@ -884,6 +890,7 @@ void CSpellHandler::beforeValidate(JsonNode & object)
 	inheritNode("basic");
 	inheritNode("advanced");
 	inheritNode("expert");
+
 }
 
 

+ 20 - 40
lib/FunctionList.h

@@ -15,71 +15,51 @@
 template<typename Signature>
 class CFunctionList
 {
-public:
 	std::vector<std::function<Signature> > funcs;
+public:
+	CFunctionList( std::nullptr_t ) { }
+	CFunctionList( int ) { }
+	CFunctionList( ){ }
 
-	CFunctionList(int){};
-	CFunctionList(){};
 	template <typename Functor> 
 	CFunctionList(const Functor &f)
 	{
 		funcs.push_back(std::function<Signature>(f));
 	}
+
 	CFunctionList(const std::function<Signature> &first)
 	{
 		if (first)
 			funcs.push_back(first);
 	}
-	CFunctionList(std::nullptr_t)
-	{}
-	CFunctionList & operator+=(const std::function<Signature> &first)
-	{
-		funcs.push_back(first);
-		return *this;
-	}
-	void add(const CFunctionList<Signature> &first)
+
+	CFunctionList & operator+=(const CFunctionList<Signature> &first)
 	{
-		for (size_t i = 0; i < first.funcs.size(); i++)
+		for( auto & fun : first.funcs)
 		{
-			funcs.push_back(first.funcs[i]);
+			funcs.push_back(fun);
 		}
+		return *this;
 	}
+
 	void clear()
 	{
 		funcs.clear();
 	}
+
 	operator bool() const
 	{
-		return funcs.size();
+		return !funcs.empty();
 	}
-	void operator()() const
-	{
-		std::vector<std::function<Signature> > funcs2 = funcs; //backup
-		for(size_t i=0;i<funcs2.size(); ++i) 
-		{
-			if (funcs2[i])
-				funcs2[i]();
-		}
-	}
-	template <typename Arg> 
-	void operator()(const Arg & a) const
-	{
-		std::vector<std::function<Signature> > funcs2 = funcs; //backup
-		for(int i=0;i<funcs2.size(); i++) 
-		{
-			if (funcs2[i])
-				funcs2[i](a);
-		}
-	}
-	// Me wants variadic templates :(
-	template <typename Arg1, typename Arg2>
-	void operator()(Arg1 & a, Arg2 & b) const
+
+	template <typename... Args>
+	void operator()(Args ... args) const
 	{
-		std::vector<std::function<Signature> > funcs2 = funcs; //backup
-		for(int i=0;i<funcs2.size(); i++)
+		std::vector<std::function<Signature> > funcs_copy = funcs;
+		for( auto & fun : funcs_copy)
 		{
-			if (funcs2[i])
-				funcs2[i](a, b);
+			if (fun)
+				fun(args...);
 		}
 	}
 };