From ef954b8a4f0d040689ea433d9d6d480aa84fcb5b Mon Sep 17 00:00:00 2001 From: DjWarmonger Date: Sun, 17 Jul 2011 18:11:03 +0000 Subject: [PATCH] Most of the stuff I've commited today makes no sense, proper solution is trivial. --- server/CGameHandler.cpp | 51 +++++++++++++---------------------------- server/CGameHandler.h | 4 ++-- 2 files changed, 18 insertions(+), 37 deletions(-) diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index 356b5e0f1..a129a4344 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -201,8 +201,8 @@ void CGameHandler::levelUpHero(int ID) if (hero->battle) tlog1<<"Battle found\n"; if (hero->exp < VLC->heroh->reqExp(hero->level+1)) - {// no more level-ups - afterBattleCallback(0); + {// no more level-ups, call end battle + afterBattleCallback(); return; } @@ -267,41 +267,20 @@ void CGameHandler::levelUpHero(int ID) hlu.skills.push_back(hero->type->heroClass->chooseSecSkill(basicAndAdv)); //upgrade existing } - if (hero->exp >= VLC->heroh->reqExp(hero->level+2)) // more level-ups + if(hlu.skills.size() > 1) //apply and ask for secondary skill { - if(hlu.skills.size() > 1) //apply and ask for secondary skill - { - boost::function callback = boost::function(boost::bind(callWith,hlu.skills,boost::function(boost::bind(&CGameHandler::levelUpHero,this,ID,_1)),_1)); - applyAndAsk(&hlu,hero->tempOwner,callback); //call levelUpHero when client responds - } - else if(hlu.skills.size() == 1) //apply, give only possible skill and send info - { - sendAndApply(&hlu); - levelUpHero(ID, hlu.skills.back()); - } - else //apply and send info - { - sendAndApply(&hlu); - levelUpHero(ID); - } + boost::function callback = boost::function(boost::bind(callWith,hlu.skills,boost::function(boost::bind(&CGameHandler::levelUpHero,this,ID,_1)),_1)); + applyAndAsk(&hlu,hero->tempOwner,callback); //call levelUpHero when client responds } - else //call function after battle was finished and all exp given + else if(hlu.skills.size() == 1) //apply, give only possible skill and send info { - boost::function callback = boost::function(boost::bind(callWith,hlu.skills,boost::function(boost::bind(&CGameHandler::afterBattleCallback,this,_1)),_1)); - if(hlu.skills.size() > 1) //apply and ask for secondary skill - { - applyAndAsk(&hlu, hero->tempOwner, callback); //call levelUpHero when client responds - } - else if(hlu.skills.size() == 1) //apply, give only possible skill and send info - { - applyAndAsk(&hlu, hero->tempOwner, callback); //call levelUpHero when client responds - levelUpHero(ID, hlu.skills.back()); - } - else //apply and send info - { - applyAndAsk(&hlu, hero->tempOwner, callback); //call levelUpHero when client responds - levelUpHero(ID); - } + sendAndApply(&hlu); + levelUpHero(ID, hlu.skills.back()); + } + else //apply and send info + { + sendAndApply(&hlu); + levelUpHero(ID); } } @@ -457,6 +436,8 @@ void CGameHandler::endBattle(int3 tile, const CGHeroInstance *hero1, const CGHer changePrimSkill(hero1->id,4,battleResult.data->exp[0]); if(battleResult.data->exp[1] && hero2) changePrimSkill(hero2->id,4,battleResult.data->exp[1]); + if (!(hero1 || hero2)) //possible? + afterBattleCallback(); //clear stuff for sanity } sendAndApply(&resultsApplied); @@ -518,7 +499,7 @@ void CGameHandler::endBattle(int3 tile, const CGHeroInstance *hero1, const CGHer } } -void CGameHandler::afterBattleCallback(int ID) //object interaction after leveling up is done +void CGameHandler::afterBattleCallback() //object interaction after leveling up is done { if(battleEndCallback && *battleEndCallback) { diff --git a/server/CGameHandler.h b/server/CGameHandler.h index 9c01fe46b..14422114e 100644 --- a/server/CGameHandler.h +++ b/server/CGameHandler.h @@ -182,9 +182,9 @@ public: void visitObjectOnTile(const TerrainTile &t, const CGHeroInstance * h); bool teleportHero(si32 hid, si32 dstid, ui8 source, ui8 asker = 255); void vistiCastleObjects (const CGTownInstance *t, const CGHeroInstance *h); - void levelUpHero(int ID, int skill);//handle client respond and send one more request if needed + void levelUpHero(int ID, int skill);//handle client respond and send one more request if needed void levelUpHero(int ID);//initial call - check if hero have remaining levelups & handle them - void afterBattleCallback(int ID); // called after level-ups are finished, ID is just temporarily for compatibility + void afterBattleCallback(); // called after level-ups are finished, ID is just temporarily for compatibility ////////////////////////////////////////////////////////////////////////// void commitPackage(CPackForClient *pack) OVERRIDE;