From 2a7ad63495a9e38ebc3b9c04e04022b18150d7ae Mon Sep 17 00:00:00 2001 From: mateuszb Date: Sat, 21 Mar 2009 16:03:07 +0000 Subject: [PATCH] * massive spells go via one SetStackEffect --- CBattleInterface.cpp | 124 +++++++++----------------------------- CBattleInterface.h | 2 + CGameInterface.h | 2 + CPlayerInterface.cpp | 5 ++ CPlayerInterface.h | 1 + client/NetPacksClient.cpp | 14 ++--- lib/IGameCallback.h | 2 +- server/CGameHandler.cpp | 40 ++++++------ 8 files changed, 67 insertions(+), 123 deletions(-) diff --git a/CBattleInterface.cpp b/CBattleInterface.cpp index a1bc8d55c..6bf5deef7 100644 --- a/CBattleInterface.cpp +++ b/CBattleInterface.cpp @@ -248,6 +248,26 @@ CBattleInterface::CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, C SDL_SetColorKey(idToObstacle[obst[t].ID]->ourImages[n].bitmap, SDL_SRCCOLORKEY, SDL_MapRGB(idToObstacle[obst[t].ID]->ourImages[n].bitmap->format,0,255,255)); } } + + //initializing spellToEffect + spellToEffect[17] = 1; //lightning bolt + spellToEffect[18] = 10; //implosion + spellToEffect[27] = 27; //shield + spellToEffect[28] = 2; //air shield + spellToEffect[41] = 36; //bless + spellToEffect[42] = 40; //curse + spellToEffect[43] = 4; //bloodlust + spellToEffect[45] = 56; //weakness + spellToEffect[46] = 54; //stone skin + spellToEffect[48] = 0; //prayer + spellToEffect[49] = 20; //mirth + spellToEffect[50] = 30; //sorrow + spellToEffect[51] = 18; //fortune + spellToEffect[52] = 48; //misfortune + spellToEffect[53] = 31; //haste + spellToEffect[54] = 19; //slow + spellToEffect[56] = 17; //frenzy + spellToEffect[61] = 42; //forgetfulness } CBattleInterface::~CBattleInterface() @@ -1710,98 +1730,14 @@ void CBattleInterface::spellCasted(SpellCasted * sc) SDL_SetClipRect(screen, &buf); //restoring previous clip rect break; //for 15 and 16 cases } - case 17: //lightning bolt - { - displayEffect(1, sc->tile); - break; - } - case 18: //implosion - { - displayEffect(10, sc->tile); - break; - } - case 27: //shield - { - displayEffect(27, sc->tile); - break; - } - case 28: //air shield - { - displayEffect(2, sc->tile); - break; - } - case 41: //bless - { - displayEffect(36, sc->tile); - break; - } - case 42: //curse - { - displayEffect(40, sc->tile); - break; - } - case 43: //bloodlust - { - displayEffect(4, sc->tile); - //TODO: give better animation for this spell - break; - } - case 45: //weakness - { - displayEffect(56, sc->tile); - //TODO: give better animation for this spell - break; - } - case 46: //stone skin - { - displayEffect(54, sc->tile); - break; - } - case 48: //prayer - { - displayEffect(0, sc->tile); - break; - } - case 49: //mirth - { - displayEffect(20, sc->tile); - break; - } - case 50: //sorrow - { - displayEffect(30, sc->tile); - break; - } - case 51: //fortune - { - displayEffect(18, sc->tile); - break; - } - case 52: //misfortune - { - displayEffect(48, sc->tile); - break; - } - case 53: //haste - { - displayEffect(31, sc->tile); - break; - } - case 54: //slow - { - displayEffect(19, sc->tile); - break; - } - case 56: //frenzy - { - displayEffect(17, sc->tile); - break; - } - case 61: //forgetfulness - { - displayEffect(42, sc->tile); - break; - } + } +} + +void CBattleInterface::battleStacksEffectsSet(const SetStackEffect & sse) +{ + for(std::set::const_iterator ci = sse.stacks.begin(); ci!=sse.stacks.end(); ++ci) + { + displayEffect(spellToEffect[sse.effect.id], LOCPLINT->cb->battleGetStackByID(*ci)->position); } } @@ -1819,7 +1755,7 @@ void CBattleInterface::castThisSpell(int spellID) //choosing possible tragets const CGHeroInstance * castingHero = (attackingHeroInstance->tempOwner == LOCPLINT->playerID) ? attackingHeroInstance : attackingHeroInstance; spellSelMode = 0; - if(CGI->spellh->spells[spellID].attributes.find("CREATURE_TARGET") != std::string::npos) + if(CGI->spellh->spells[spellID].attributes.find("CREATURE_TARGET") != std::string::npos) //spell to be cast on one specific creature { switch(CGI->spellh->spells[spellID].positiveness) { @@ -1834,7 +1770,7 @@ void CBattleInterface::castThisSpell(int spellID) break; } } - if(CGI->spellh->spells[spellID].attributes.find("CREATURE_TARGET_2") != std::string::npos) + if(CGI->spellh->spells[spellID].attributes.find("CREATURE_TARGET_2") != std::string::npos) //spell to be cast on a specific creature but massive on expert { if(castingHero && castingHero->getSpellSecLevel(spellID) < 3) { diff --git a/CBattleInterface.h b/CBattleInterface.h index fcf6dde57..d2e146146 100644 --- a/CBattleInterface.h +++ b/CBattleInterface.h @@ -135,6 +135,7 @@ private: std::map< int, CDefHandler * > idToProjectile; //projectiles of creaures (creatureID, defhandler) std::map< int, CDefHandler * > idToObstacle; //obstacles located on the battlefield std::map< int, bool > creDir; // + std::map< int, int > spellToEffect; //which effect should be played when different spells are casted (spellID, effectID) unsigned char animCount; int activeStack; //number of active stack; -1 - no one int mouseHoveredStack; //stack hovered by mouse; if -1 -> none @@ -257,6 +258,7 @@ public: void stackIsShooting(int ID, int dest); //called when stack with id ID is shooting to hex dest void battleFinished(const BattleResult& br); //called when battle is finished - battleresult window should be printed void spellCasted(SpellCasted * sc); //called when a hero casts a spell + void battleStacksEffectsSet(const SetStackEffect & sse); //called when a specific effect is set to stacks void castThisSpell(int spellID); //called when player has chosen a spell from spellbook void displayEffect(ui32 effect, int destTile); //displays effect of a spell on the battlefield; affected: true - attacker. false - defender diff --git a/CGameInterface.h b/CGameInterface.h index a989cc7bb..8082479ed 100644 --- a/CGameInterface.h +++ b/CGameInterface.h @@ -23,6 +23,7 @@ struct BattleResult; struct BattleAttack; struct BattleStackAttacked; struct SpellCasted; +struct SetStackEffect; struct HeroBonus; class CObstacle { @@ -80,6 +81,7 @@ public: virtual void battleNewRound(int round){}; //called at the beggining of each turn, round=-1 is the tactic phase, round=0 is the first "normal" turn virtual void battleStackMoved(int ID, int dest, int distance){}; virtual void battleSpellCasted(SpellCasted *sc){}; + virtual void battleStacksEffectsSet(SetStackEffect & sse){};//called when a specific effect is set to stacks virtual void battleStart(CCreatureSet *army1, CCreatureSet *army2, int3 tile, CGHeroInstance *hero1, CGHeroInstance *hero2, bool side){}; //called by engine when battle starts; side=0 - left, side=1 - right virtual void battlefieldPrepared(int battlefieldType, std::vector obstacles){}; //called when battlefield is prepared, prior the battle beginning }; diff --git a/CPlayerInterface.cpp b/CPlayerInterface.cpp index d052ba8a1..6e9ede2ec 100644 --- a/CPlayerInterface.cpp +++ b/CPlayerInterface.cpp @@ -2288,6 +2288,11 @@ void CPlayerInterface::battleSpellCasted(SpellCasted *sc) boost::unique_lock un(*pim); battleInt->spellCasted(sc); } +void CPlayerInterface::battleStacksEffectsSet(SetStackEffect & sse) +{ + boost::unique_lock un(*pim); + battleInt->battleStacksEffectsSet(sse); +} void CPlayerInterface::battleStacksAttacked(std::set & bsa) { tlog5 << "CPlayerInterface::battleStackAttacked - locking..."; diff --git a/CPlayerInterface.h b/CPlayerInterface.h index 4f4f6376d..b6b707997 100644 --- a/CPlayerInterface.h +++ b/CPlayerInterface.h @@ -495,6 +495,7 @@ public: void battleNewRound(int round); //called at the beggining of each turn, round=-1 is the tactic phase, round=0 is the first "normal" turn void battleStackMoved(int ID, int dest, int distance); void battleSpellCasted(SpellCasted *sc); + void battleStacksEffectsSet(SetStackEffect & sse); //called when a specific effect is set to stacks void battleStacksAttacked(std::set & bsa); void battleStart(CCreatureSet *army1, CCreatureSet *army2, int3 tile, CGHeroInstance *hero1, CGHeroInstance *hero2, bool side); //called by engine when battle starts; side=0 - left, side=1 - right void battlefieldPrepared(int battlefieldType, std::vector obstacles); //called when battlefield is prepared, prior the battle beginning diff --git a/client/NetPacksClient.cpp b/client/NetPacksClient.cpp index c749fb4b2..e07ad4075 100644 --- a/client/NetPacksClient.cpp +++ b/client/NetPacksClient.cpp @@ -379,14 +379,12 @@ void SetStackEffect::applyCl( CClient *cl ) sc.id = effect.id; sc.side = 3; //doesn't matter sc.skill = effect.level; - BOOST_FOREACH(ui32 stack, stacks) - { - sc.tile = GS(cl)->curB->getStack(stack)->position; - if(cl->playerint.find(GS(cl)->curB->side1) != cl->playerint.end()) - cl->playerint[GS(cl)->curB->side1]->battleSpellCasted(&sc); - if(cl->playerint.find(GS(cl)->curB->side2) != cl->playerint.end()) - cl->playerint[GS(cl)->curB->side2]->battleSpellCasted(&sc); - } + + //informing about effects + if(cl->playerint.find(GS(cl)->curB->side1) != cl->playerint.end()) + cl->playerint[GS(cl)->curB->side1]->battleStacksEffectsSet(*this); + if(cl->playerint.find(GS(cl)->curB->side2) != cl->playerint.end()) + cl->playerint[GS(cl)->curB->side2]->battleStacksEffectsSet(*this); } CGameState* CPackForClient::GS( CClient *cl ) diff --git a/lib/IGameCallback.h b/lib/IGameCallback.h index 815cbd309..873247308 100644 --- a/lib/IGameCallback.h +++ b/lib/IGameCallback.h @@ -36,7 +36,7 @@ public: virtual const CGTownInstance* getTown(int objid); virtual const CGHeroInstance* getSelectedHero(int player); //NULL if no hero is selected virtual int getCurrentPlayer()=0; - virtual int getSelectedHero()=0; + virtual int getSelectedHero()=0; virtual const PlayerSettings * getPlayerSettings(int color); virtual int getHeroCount(int player, bool includeGarrisoned); virtual void getTilesInRange(std::set &tiles, int3 pos, int radious, int player=-1, int mode=0); //mode 1 - only unrevealed tiles; mode 0 - all, mode -1 - only unrevealed diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index 6eb195e4f..dfd39c1e2 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -2226,30 +2226,30 @@ void CGameHandler::makeCustomAction( BattleAction &ba ) //TODO: check resistances #define SPELL_CAST_TEMPLATE_1(NUMBER, DURATION) SetStackEffect sse; \ -if(getSchoolLevel(h,s) < 3) /*not expert */ \ + if(getSchoolLevel(h,s) < 3) /*not expert */ \ { \ - sse.stacks.insert(gs->curB->getStackT(ba.destinationTile)->ID); \ - sse.effect.id = (NUMBER); \ - sse.effect.level = getSchoolLevel(h,s); \ - sse.effect.turnsRemain = (DURATION); /*! - any duration */ \ - sendAndApply(&sse); \ + sse.stacks.insert(gs->curB->getStackT(ba.destinationTile)->ID); \ + sse.effect.id = (NUMBER); \ + sse.effect.level = getSchoolLevel(h,s); \ + sse.effect.turnsRemain = (DURATION); /*! - any duration */ \ + sendAndApply(&sse); \ } \ else \ { \ - for(int it=0; itcurB->stacks.size(); ++it) \ - { \ - /*if it's non negative spell and our unit or non positive spell and hostile unit */ \ - if((VLC->spellh->spells[ba.additionalInfo].positiveness >= 0 && gs->curB->stacks[it]->owner == h->tempOwner) \ - ||(VLC->spellh->spells[ba.additionalInfo].positiveness <= 0 && gs->curB->stacks[it]->owner != h->tempOwner ) \ - ) \ - { \ - sse.stacks.insert(gs->curB->stacks[it]->ID); \ - sse.effect.id = (NUMBER); \ - sse.effect.level = getSchoolLevel(h,s); \ - sse.effect.turnsRemain = (DURATION); \ - sendAndApply(&sse); \ - } \ - } \ + for(int it=0; itcurB->stacks.size(); ++it) \ + { \ + /*if it's non negative spell and our unit or non positive spell and hostile unit */ \ + if((VLC->spellh->spells[ba.additionalInfo].positiveness >= 0 && gs->curB->stacks[it]->owner == h->tempOwner) \ + ||(VLC->spellh->spells[ba.additionalInfo].positiveness <= 0 && gs->curB->stacks[it]->owner != h->tempOwner ) \ + ) \ + { \ + sse.stacks.insert(gs->curB->stacks[it]->ID); \ + } \ + } \ + sse.effect.id = (NUMBER); \ + sse.effect.level = getSchoolLevel(h,s); \ + sse.effect.turnsRemain = (DURATION); \ + sendAndApply(&sse); \ } SpellCasted sc;