mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
* small refactoring
This commit is contained in:
parent
df25dd7efb
commit
621400ac85
@ -1,6 +1,5 @@
|
||||
#include "../../AI_Base.h"
|
||||
#include "../../CCallback.h"
|
||||
#include "../../hch/CSoundBase.h"
|
||||
|
||||
class CEmptyAI : public CGlobalAI
|
||||
{
|
||||
@ -15,7 +14,7 @@ public:
|
||||
void showSelDialog(std::string text, std::vector<CSelectableComponent*> & components, int askID){};
|
||||
void tileRevealed(int3 pos){};
|
||||
void tileHidden(int3 pos){};
|
||||
void showBlockingDialog(const std::string &text, const std::vector<Component> &components, ui32 askID, soundBase::soundID soundID, bool selection, bool cancel){};
|
||||
void showBlockingDialog(const std::string &text, const std::vector<Component> &components, ui32 askID, int soundID, bool selection, bool cancel){};
|
||||
void showGarrisonDialog(const CArmedInstance *up, const CGHeroInstance *down, boost::function<void()> &onEnd){};
|
||||
void heroGotLevel(const CGHeroInstance *hero, int pskill, std::vector<ui16> &skills, boost::function<void(ui32)> &callback);
|
||||
};
|
||||
|
@ -69,7 +69,7 @@ void GeniusAI::CGeniusAI::showGarrisonDialog( const CArmedInstance *up, const CG
|
||||
onEnd();
|
||||
}
|
||||
|
||||
void CGeniusAI::showBlockingDialog( const std::string &text, const std::vector<Component> &components, ui32 askID, soundBase::soundID soundID, bool selection, bool cancel )
|
||||
void CGeniusAI::showBlockingDialog( const std::string &text, const std::vector<Component> &components, ui32 askID, int soundID, bool selection, bool cancel )
|
||||
{
|
||||
m_cb->selectionMade(cancel ? 0 : 1, askID);
|
||||
}
|
||||
|
@ -190,7 +190,7 @@ public:
|
||||
virtual void heroMoved(const HeroMoveDetails &);
|
||||
virtual void heroPrimarySkillChanged(const CGHeroInstance * hero, int which, int val) {};
|
||||
virtual void showSelDialog(std::string text, std::vector<CSelectableComponent*> & components, int askID){};
|
||||
virtual void showBlockingDialog(const std::string &text, const std::vector<Component> &components, ui32 askID, soundBase::soundID soundID, bool selection, bool cancel);
|
||||
virtual void showBlockingDialog(const std::string &text, const std::vector<Component> &components, ui32 askID, int soundID, bool selection, bool cancel);
|
||||
virtual void tileRevealed(int3 pos){};
|
||||
virtual void tileHidden(int3 pos){};
|
||||
virtual void heroGotLevel(const CGHeroInstance *hero, int pskill, std::vector<ui16> &skills, boost::function<void(ui32)> &callback);
|
||||
|
@ -80,10 +80,10 @@ public:
|
||||
virtual void heroVisitsTown(const CGHeroInstance* hero, const CGTownInstance * town){};
|
||||
virtual void init(ICallback * CB){};
|
||||
virtual void receivedResource(int type, int val){};
|
||||
virtual void showInfoDialog(const std::string &text, const std::vector<Component*> &components, soundBase::soundID soundID){};
|
||||
virtual void showInfoDialog(const std::string &text, const std::vector<Component*> &components, int soundID){};
|
||||
//virtual void showSelDialog(const std::string &text, const std::vector<Component*> &components, ui32 askID){};
|
||||
//virtual void showYesNoDialog(const std::string &text, const std::vector<Component*> &components, ui32 askID){};
|
||||
virtual void showBlockingDialog(const std::string &text, const std::vector<Component> &components, ui32 askID, const soundBase::soundID soundID, bool selection, bool cancel) = 0; //Show a dialog, player must take decision. If selection then he has to choose between one of given components, if cancel he is allowed to not choose. After making choice, CCallback::selectionMade should be called with number of selected component (1 - n) or 0 for cancel (if allowed) and askID.
|
||||
virtual void showBlockingDialog(const std::string &text, const std::vector<Component> &components, ui32 askID, const int soundID, bool selection, bool cancel) = 0; //Show a dialog, player must take decision. If selection then he has to choose between one of given components, if cancel he is allowed to not choose. After making choice, CCallback::selectionMade should be called with number of selected component (1 - n) or 0 for cancel (if allowed) and askID.
|
||||
virtual void showGarrisonDialog(const CArmedInstance *up, const CGHeroInstance *down, boost::function<void()> &onEnd) = 0; //all stacks operations between these objects become allowed, interface has to call onEnd when done
|
||||
virtual void tileHidden(const std::set<int3> &pos){};
|
||||
virtual void tileRevealed(const std::set<int3> &pos){};
|
||||
|
@ -2409,7 +2409,7 @@ void CPlayerInterface::showComp(SComponent comp)
|
||||
adventureInt->infoBar.showComp(&comp,4000);
|
||||
}
|
||||
|
||||
void CPlayerInterface::showInfoDialog(const std::string &text, const std::vector<Component*> &components, soundBase::soundID soundID)
|
||||
void CPlayerInterface::showInfoDialog(const std::string &text, const std::vector<Component*> &components, int soundID)
|
||||
{
|
||||
std::vector<SComponent*> intComps;
|
||||
for(int i=0;i<components.size();i++)
|
||||
@ -2417,7 +2417,7 @@ void CPlayerInterface::showInfoDialog(const std::string &text, const std::vector
|
||||
showInfoDialog(text,intComps,soundID);
|
||||
}
|
||||
|
||||
void CPlayerInterface::showInfoDialog(const std::string &text, const std::vector<SComponent*> & components, soundBase::soundID soundID)
|
||||
void CPlayerInterface::showInfoDialog(const std::string &text, const std::vector<SComponent*> & components, int soundID)
|
||||
{
|
||||
{
|
||||
boost::unique_lock<boost::mutex> un(showingDialog->mx);
|
||||
@ -2436,7 +2436,7 @@ void CPlayerInterface::showInfoDialog(const std::string &text, const std::vector
|
||||
|
||||
if(makingTurn && listInt.size())
|
||||
{
|
||||
CGI->mush->playSound(soundID);
|
||||
CGI->mush->playSound(static_cast<soundBase::soundID>(soundID));
|
||||
showingDialog->set(true);
|
||||
pushInt(temp);
|
||||
}
|
||||
@ -2463,11 +2463,11 @@ void CPlayerInterface::showYesNoDialog(const std::string &text, const std::vecto
|
||||
LOCPLINT->pushInt(temp);
|
||||
}
|
||||
|
||||
void CPlayerInterface::showBlockingDialog( const std::string &text, const std::vector<Component> &components, ui32 askID, soundBase::soundID soundID, bool selection, bool cancel )
|
||||
void CPlayerInterface::showBlockingDialog( const std::string &text, const std::vector<Component> &components, ui32 askID, int soundID, bool selection, bool cancel )
|
||||
{
|
||||
boost::unique_lock<boost::recursive_mutex> un(*pim);
|
||||
|
||||
CGI->mush->playSound(soundID);
|
||||
CGI->mush->playSound(static_cast<soundBase::soundID>(soundID));
|
||||
|
||||
if(!selection && cancel) //simple yes/no dialog
|
||||
{
|
||||
|
@ -592,10 +592,10 @@ public:
|
||||
void heroMovePointsChanged(const CGHeroInstance * hero);
|
||||
void heroVisitsTown(const CGHeroInstance* hero, const CGTownInstance * town);
|
||||
void receivedResource(int type, int val);
|
||||
void showInfoDialog(const std::string &text, const std::vector<Component*> &components, soundBase::soundID soundID);
|
||||
void showInfoDialog(const std::string &text, const std::vector<Component*> &components, int soundID);
|
||||
//void showSelDialog(const std::string &text, const std::vector<Component*> &components, ui32 askID);
|
||||
//void showYesNoDialog(const std::string &text, const std::vector<Component*> &components, ui32 askID);
|
||||
void showBlockingDialog(const std::string &text, const std::vector<Component> &components, ui32 askID, soundBase::soundID soundID, bool selection, bool cancel); //Show a dialog, player must take decision. If selection then he has to choose between one of given components, if cancel he is allowed to not choose. After making choice, CCallback::selectionMade should be called with number of selected component (1 - n) or 0 for cancel (if allowed) and askID.
|
||||
void showBlockingDialog(const std::string &text, const std::vector<Component> &components, ui32 askID, int soundID, bool selection, bool cancel); //Show a dialog, player must take decision. If selection then he has to choose between one of given components, if cancel he is allowed to not choose. After making choice, CCallback::selectionMade should be called with number of selected component (1 - n) or 0 for cancel (if allowed) and askID.
|
||||
void showGarrisonDialog(const CArmedInstance *up, const CGHeroInstance *down, boost::function<void()> &onEnd);
|
||||
void tileHidden(const std::set<int3> &pos);
|
||||
void tileRevealed(const std::set<int3> &pos);
|
||||
@ -636,7 +636,7 @@ public:
|
||||
void handleMouseMotion(SDL_Event *sEvent);
|
||||
void init(ICallback * CB);
|
||||
int3 repairScreenPos(int3 pos); //returns position closest to pos we can center screen on
|
||||
void showInfoDialog(const std::string &text, const std::vector<SComponent*> & components, soundBase::soundID soundID);
|
||||
void showInfoDialog(const std::string &text, const std::vector<SComponent*> & components, int soundID);
|
||||
void showYesNoDialog(const std::string &text, const std::vector<SComponent*> & components, CFunctionList<void()> onYes, CFunctionList<void()> onNo, bool DelComps); //deactivateCur - whether current main interface should be deactivated; delComps - if components will be deleted on window close
|
||||
bool moveHero(const CGHeroInstance *h, CPath path);
|
||||
|
||||
|
@ -2356,20 +2356,6 @@ bool CGameHandler::makeCustomAction( BattleAction &ba )
|
||||
|
||||
//TODO: check resistances
|
||||
|
||||
#define SPELL_CAST_TEMPLATE_2 \
|
||||
StacksInjured si; \
|
||||
for(std::set<CStack*>::iterator it = attackedCres.begin(); it != attackedCres.end(); ++it) \
|
||||
{ \
|
||||
BattleStackAttacked bsa; \
|
||||
bsa.flags |= 2; \
|
||||
bsa.effect = VLC->spellh->spells[ba.additionalInfo].mainEffectAnim; \
|
||||
bsa.damageAmount = calculateSpellDmg(&VLC->spellh->spells[ba.additionalInfo], h, *it); \
|
||||
bsa.stackAttacked = (*it)->ID; \
|
||||
prepareAttacked(bsa,*it); \
|
||||
si.stacks.insert(bsa); \
|
||||
} \
|
||||
sendAndApply(&si); \
|
||||
|
||||
SpellCasted sc;
|
||||
sc.side = ba.side;
|
||||
sc.id = ba.additionalInfo;
|
||||
@ -2377,11 +2363,23 @@ bool CGameHandler::makeCustomAction( BattleAction &ba )
|
||||
sc.tile = ba.destinationTile;
|
||||
sendAndApply(&sc);
|
||||
|
||||
//calculating affected creatures - not for all spells, but for many of them
|
||||
//it should spoil anything for other spells
|
||||
//calculating affected creatures for all spells ///////////////////
|
||||
std::set<ui16> attackedHexes = s->rangeInHexes(ba.destinationTile, h->getSpellSchoolLevel(s));
|
||||
std::set<CStack*> attackedCres; /*std::set to exclude multiple occurences of two hex creatures*/
|
||||
if(VLC->spellh->spells[ba.additionalInfo].attributes.find("CREATURE_TARGET_2") != std::string::npos) //spell to be cast on a specific creature but massive on expert
|
||||
if(ba.additionalInfo == 24 || ba.additionalInfo == 25 || ba.additionalInfo == 26) //death ripple, destroy undead and armageddon
|
||||
{
|
||||
for(int it=0; it<gs->curB->stacks.size(); ++it)
|
||||
{
|
||||
if((ba.additionalInfo == 24 && !gs->curB->stacks[it]->creature->isUndead()) //death ripple
|
||||
|| (ba.additionalInfo == 25 && gs->curB->stacks[it]->creature->isUndead()) //destroy undead
|
||||
|| (ba.additionalInfo == 26) //armageddon
|
||||
)
|
||||
{
|
||||
attackedCres.insert(gs->curB->stacks[it]);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(VLC->spellh->spells[ba.additionalInfo].attributes.find("CREATURE_TARGET_2") != std::string::npos) //spell to be cast on a specific creature but massive on expert
|
||||
{
|
||||
if(h->getSpellSchoolLevel(s) < 3) /*not expert */
|
||||
{
|
||||
@ -2430,46 +2428,22 @@ bool CGameHandler::makeCustomAction( BattleAction &ba )
|
||||
case 21: //fireball
|
||||
case 22: //inferno
|
||||
case 23: //meteor shower
|
||||
{
|
||||
SPELL_CAST_TEMPLATE_2;
|
||||
break;
|
||||
}
|
||||
case 24: //death ripple
|
||||
{
|
||||
std::set<CStack*> attackedCres;
|
||||
|
||||
for(int it=0; it<gs->curB->stacks.size(); ++it)
|
||||
{
|
||||
if(!gs->curB->stacks[it]->creature->isUndead())
|
||||
attackedCres.insert(gs->curB->stacks[it]);
|
||||
}
|
||||
if(attackedCres.size() == 0) break;
|
||||
SPELL_CAST_TEMPLATE_2;
|
||||
break;
|
||||
}
|
||||
case 25: //destroy undead
|
||||
{
|
||||
std::set<CStack*> attackedCres;
|
||||
|
||||
for(int it=0; it<gs->curB->stacks.size(); ++it)
|
||||
{
|
||||
if(gs->curB->stacks[it]->creature->isUndead())
|
||||
attackedCres.insert(gs->curB->stacks[it]);
|
||||
}
|
||||
if(attackedCres.size() == 0) break;
|
||||
SPELL_CAST_TEMPLATE_2;
|
||||
break;
|
||||
}
|
||||
case 26: //armageddon
|
||||
{
|
||||
std::set<CStack*> attackedCres;
|
||||
|
||||
for(int it=0; it<gs->curB->stacks.size(); ++it)
|
||||
StacksInjured si;
|
||||
for(std::set<CStack*>::iterator it = attackedCres.begin(); it != attackedCres.end(); ++it)
|
||||
{
|
||||
attackedCres.insert(gs->curB->stacks[it]);
|
||||
BattleStackAttacked bsa;
|
||||
bsa.flags |= 2;
|
||||
bsa.effect = VLC->spellh->spells[ba.additionalInfo].mainEffectAnim;
|
||||
bsa.damageAmount = calculateSpellDmg(&VLC->spellh->spells[ba.additionalInfo], h, *it);
|
||||
bsa.stackAttacked = (*it)->ID;
|
||||
prepareAttacked(bsa,*it);
|
||||
si.stacks.insert(bsa);
|
||||
}
|
||||
if(attackedCres.size() == 0) break;
|
||||
SPELL_CAST_TEMPLATE_2;
|
||||
sendAndApply(&si);
|
||||
break;
|
||||
}
|
||||
case 27: //shield
|
||||
|
Loading…
Reference in New Issue
Block a user