1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Fixes for r2543.

This commit is contained in:
DjWarmonger 2012-02-20 09:50:49 +00:00
parent 444b59d478
commit 5e14d17ed3
5 changed files with 39 additions and 27 deletions

View File

@ -954,7 +954,7 @@ void CBattleInterface::mouseMoved(const SDL_MouseMotionEvent &sEvent)
if (shere != sactive) //can't cast on itself
{
const CSpell * spell = CGI->spellh->spells[creatureSpellToCast];
if (curInt->cb->battleCanCastThisSpell(spell, BattleHex(myNumber)) == ESpellCastProblem::OK)
if (curInt->cb->battleCanCreatureCastThisSpell(spell, BattleHex(myNumber)) == ESpellCastProblem::OK)
{
if ((!spell->isNegative() && ourStack) || (!spell->isPositive() && !ourStack))
{
@ -1159,7 +1159,8 @@ void CBattleInterface::mouseMoved(const SDL_MouseMotionEvent &sEvent)
case SpellSelectionType::ANY_LOCATION:
CCS->curh->changeGraphic(3, 0);
//setting console text
consoleMsg += CGI->generaltexth->allTexts[26] += CGI->spellh->spells[spellToCast->additionalInfo]->name;
consoleMsg += CGI->generaltexth->allTexts[26];
boost::replace_first (consoleMsg, "%s", CGI->spellh->spells[spellToCast->additionalInfo]->name);
console->alterText (consoleMsg);
console->whoSetAlter = 0;
break;
@ -1169,12 +1170,13 @@ void CBattleInterface::mouseMoved(const SDL_MouseMotionEvent &sEvent)
if( potentialTargetStack )
{
if (curInt->cb->battleCanCastThisSpell (CGI->spellh->spells[spellToCast->additionalInfo], BattleHex(myNumber)))
CCS->curh->changeGraphic(3, 0);
else
CCS->curh->changeGraphic(1, 0);
else
CCS->curh->changeGraphic(3, 0);
//setting console text
consoleMsg += CGI->generaltexth->allTexts[27] += CGI->spellh->spells[spellToCast->additionalInfo]->name;
consoleMsg += stackUnder->getName();
consoleMsg += CGI->generaltexth->allTexts[27];
boost::replace_first (consoleMsg, "%s", CGI->spellh->spells[spellToCast->additionalInfo]->name);
boost::replace_first (consoleMsg, "%s", stackUnder->getName());
console->alterText (consoleMsg);
console->whoSetAlter = 0;
break;
@ -1759,15 +1761,9 @@ void CBattleInterface::hexLclicked(int whichOne)
switch(spellSelMode)
{
case FRIENDLY_CREATURE:
if(!curInt->cb->battleGetStackByPos(whichOne, onlyAlive) || curInt->playerID != dest->owner )
allowCasting = false;
break;
case HOSTILE_CREATURE:
if(!curInt->cb->battleGetStackByPos(whichOne, onlyAlive) || curInt->playerID == dest->owner )
allowCasting = false;
break;
case ANY_CREATURE:
if(!curInt->cb->battleGetStackByPos(whichOne, onlyAlive))
if (curInt->cb->battleCanCastThisSpell (CGI->spellh->spells[spellToCast->additionalInfo], BattleHex(whichOne)) != ESpellCastProblem::OK)
allowCasting = false;
break;
case OBSTACLE:
@ -1800,10 +1796,13 @@ void CBattleInterface::hexLclicked(int whichOne)
//try to cast stack spell first
if (stackCanCastSpell && spellSelMode > STACK_SPELL_CANCELLED) //player did not decide to cancel this spell
{
if (dest != actSt) //can't cast on itself
{
if ((int)creatureSpellToCast > -1) //use randomized spell (Faerie Dragon), or only avaliable spell (Archangel)
{
const CSpell * spell = CGI->spellh->spells[creatureSpellToCast];
if (curInt->cb->battleCanCastThisSpell(spell, BattleHex(whichOne)) == ESpellCastProblem::OK)
{
if ((!spell->isNegative() && ourStack) || (!spell->isPositive() && !ourStack))
@ -1814,8 +1813,6 @@ void CBattleInterface::hexLclicked(int whichOne)
}
}
else if (ourStack) //must have only random positive spell (genie)
{
if (dest != actSt) //can't cast on itself
{
int spellID = curInt->cb->battleGetRandomStackSpell(dest, CBattleInfoCallback::RANDOM_GENIE);
if (spellID > -1) //can cast any spell on target stack

View File

@ -2120,9 +2120,11 @@ ESpellCastProblem::ESpellCastProblem BattleInfo::battleIsImmune(const CGHeroInst
case Spells::TELEPORT:
case Spells::CLONE:
if (subject->hasBonusOfType(Bonus::SIEGE_WEAPON))
return ESpellCastProblem::STACK_IMMUNE_TO_SPELL; //war machines are mmune to some spells than involve movement
if (spell->id == Spells::CLONE)
return ESpellCastProblem::STACK_IMMUNE_TO_SPELL; //war machines are immune to some spells than involve movement
if (spell->id == Spells::CLONE && caster) //TODO: how about stacks casting Clone?
{
if (vstd::contains(subject->state, EBattleStackState::CLONED))
return ESpellCastProblem::STACK_IMMUNE_TO_SPELL; //can't clone already cloned creature
int maxLevel = (std::max(caster->getSpellSchoolLevel(spell), (ui8)1) + 4);
int creLevel = subject->getCreature()->level;
if (maxLevel < creLevel) //tier 1-5 for basic, 1-6 for advanced, 1-7 for expert

View File

@ -3012,7 +3012,7 @@ void CGCreature::newTurn() const
cb->setObjProperty(id, ObjProperty::MONSTER_POWER, power); //increase temppower
}
if (GameConstants::STACK_EXP)
cb->setObjProperty(id, ObjProperty::MONSTER_EXP, 10000); //for testing purpose
cb->setObjProperty(id, ObjProperty::MONSTER_EXP, 500); //for testing purpose
}
void CGCreature::setPropertyDer(ui8 what, ui32 val)
{

View File

@ -116,6 +116,18 @@ ESpellCastProblem::ESpellCastProblem CBattleInfoCallback::battleCanCastThisSpell
return ESpellCastProblem::NO_HERO_TO_CAST_SPELL;
}
return gs->curB->battleCanCastThisSpellHere(player, spell, ECastingMode::HERO_CASTING, destination);
}
ESpellCastProblem::ESpellCastProblem CBattleInfoCallback::battleCanCreatureCastThisSpell(const CSpell * spell, BattleHex destination)
{
if(!gs->curB)
{
tlog1 << "battleCanCastThisSpell called when there is no battle!\n";
return ESpellCastProblem::NO_HERO_TO_CAST_SPELL;
}
return gs->curB->battleCanCastThisSpellHere(player, spell, ECastingMode::CREATURE_ACTIVE_CASTING, destination);
}

View File

@ -108,7 +108,8 @@ public:
bool battleCanShoot(const CStack * stack, BattleHex dest); //returns true if unit with id ID can shoot to dest
bool battleCanCastSpell(); //returns true, if caller can cast a spell
ESpellCastProblem::ESpellCastProblem battleCanCastThisSpell(const CSpell * spell); //determines if given spell can be casted (and returns problem description)
ESpellCastProblem::ESpellCastProblem battleCanCastThisSpell(const CSpell * spell, BattleHex destination); //determines if creature can cast a spell here
ESpellCastProblem::ESpellCastProblem battleCanCastThisSpell(const CSpell * spell, BattleHex destination); //if hero can cast spell here
ESpellCastProblem::ESpellCastProblem battleCanCreatureCastThisSpell(const CSpell * spell, BattleHex destination); //determines if creature can cast a spell here
ui32 battleGetRandomStackSpell(const CStack * stack, ERandomSpell mode);
bool battleCanFlee(); //returns true if caller can flee from the battle
int battleGetSurrenderCost(); //returns cost of surrendering battle, -1 if surrendering is not possible