1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-06-17 00:07:41 +02:00

More flixible way of spell cast on client side

(+) more support for custom adventure spells
This commit is contained in:
AlexVinS
2015-01-30 10:05:52 +03:00
parent c6c7552efe
commit 33f22bf2fc

View File

@ -611,9 +611,9 @@ CSpellWindow::SpellArea::SpellArea(SDL_Rect pos, CSpellWindow * owner)
void CSpellWindow::SpellArea::clickLeft(tribool down, bool previousState) void CSpellWindow::SpellArea::clickLeft(tribool down, bool previousState)
{ {
if(!down && mySpell!=-1) if(!down && mySpell != SpellID::NONE)
{ {
const CSpell *sp = CGI->spellh->objects[mySpell]; const CSpell * sp = mySpell.toSpell();
int spellCost = owner->myInt->cb->getSpellCost(sp, owner->myHero); int spellCost = owner->myInt->cb->getSpellCost(sp, owner->myHero);
if(spellCost > owner->myHero->mana) //insufficient mana if(spellCost > owner->myHero->mana) //insufficient mana
@ -625,8 +625,8 @@ void CSpellWindow::SpellArea::clickLeft(tribool down, bool previousState)
} }
//battle spell on adv map or adventure map spell during combat => display infowindow, not cast //battle spell on adv map or adventure map spell during combat => display infowindow, not cast
if((sp->combatSpell && !owner->myInt->battleInt) if((sp->isCombatSpell() && !owner->myInt->battleInt)
|| (!sp->combatSpell && owner->myInt->battleInt)) || (sp->isAdventureSpell() && owner->myInt->battleInt))
{ {
std::vector<CComponent*> hlp(1, new CComponent(CComponent::spell, mySpell, 0)); std::vector<CComponent*> hlp(1, new CComponent(CComponent::spell, mySpell, 0));
LOCPLINT->showInfoDialog(sp->getLevelInfo(schoolLevel).description, hlp); LOCPLINT->showInfoDialog(sp->getLevelInfo(schoolLevel).description, hlp);
@ -701,37 +701,17 @@ void CSpellWindow::SpellArea::clickLeft(tribool down, bool previousState)
break; break;
} }
} }
else if(!sp->combatSpell && !owner->myInt->battleInt) //adventure spell else if(sp->isAdventureSpell() && !owner->myInt->battleInt) //adventure spell and not in battle
{ {
SpellID spell = mySpell;
const CGHeroInstance *h = owner->myHero; const CGHeroInstance *h = owner->myHero;
owner->fexitb(); owner->fexitb();
switch(spell)
{ if(mySpell == SpellID::TOWN_PORTAL)
case SpellID::SUMMON_BOAT:
{
int3 pos = h->bestLocation();
if(pos.x < 0)
{
LOCPLINT->showInfoDialog(CGI->generaltexth->allTexts[334]); //There is no place to put the boat.
return;
}
}
break;
case SpellID::SCUTTLE_BOAT:
case SpellID::DIMENSION_DOOR:
adventureInt->enterCastingMode(sp);
return;
case SpellID::VISIONS:
case SpellID::VIEW_EARTH:
case SpellID::DISGUISE:
case SpellID::VIEW_AIR:
case SpellID::FLY:
case SpellID::WATER_WALK:
break;
case SpellID::TOWN_PORTAL:
{ {
//special case
//todo: move to mechanics
std::vector <int> availableTowns; std::vector <int> availableTowns;
std::vector <const CGTownInstance*> Towns = LOCPLINT->cb->getTownsInfo(true); std::vector <const CGTownInstance*> Towns = LOCPLINT->cb->getTownsInfo(true);
if (Towns.empty()) if (Towns.empty())
@ -740,7 +720,7 @@ void CSpellWindow::SpellArea::clickLeft(tribool down, bool previousState)
return; return;
} }
if (h->getSpellSchoolLevel(CGI->spellh->objects[spell]) < 2) //not advanced or expert - teleport to nearest available city if (h->getSpellSchoolLevel(sp) < 2) //not advanced or expert - teleport to nearest available city
{ {
auto nearest = Towns.cbegin(); //nearest town's iterator auto nearest = Towns.cbegin(); //nearest town's iterator
si32 dist = LOCPLINT->cb->getTown((*nearest)->id)->pos.dist2dSQ(h->pos); si32 dist = LOCPLINT->cb->getTown((*nearest)->id)->pos.dist2dSQ(h->pos);
@ -762,7 +742,7 @@ void CSpellWindow::SpellArea::clickLeft(tribool down, bool previousState)
else else
{ {
const CGTownInstance * town = LOCPLINT->cb->getTown((*nearest)->id); const CGTownInstance * town = LOCPLINT->cb->getTown((*nearest)->id);
LOCPLINT->cb->castSpell(h, spell, town->visitablePos());// - town->getVisitableOffset()); LOCPLINT->cb->castSpell(h, mySpell, town->visitablePos());// - town->getVisitableOffset());
} }
} }
else else
@ -779,19 +759,38 @@ void CSpellWindow::SpellArea::clickLeft(tribool down, bool previousState)
LOCPLINT->showInfoDialog(CGI->generaltexth->allTexts[124]); LOCPLINT->showInfoDialog(CGI->generaltexth->allTexts[124]);
else else
GH.pushInt (new CObjectListWindow(availableTowns, GH.pushInt (new CObjectListWindow(availableTowns,
new CAnimImage("SPELLSCR",spell), new CAnimImage("SPELLSCR",mySpell),
CGI->generaltexth->jktexts[40], CGI->generaltexth->jktexts[41], CGI->generaltexth->jktexts[40], CGI->generaltexth->jktexts[41],
std::bind (&CSpellWindow::teleportTo, owner, _1, h))); std::bind (&CSpellWindow::teleportTo, owner, _1, h)));
} }
return; return;
} }
break;
default: if(mySpell == SpellID::SUMMON_BOAT)
assert(0); {
//special case
//todo: move to mechanics
int3 pos = h->bestLocation();
if(pos.x < 0)
{
LOCPLINT->showInfoDialog(CGI->generaltexth->allTexts[334]); //There is no place to put the boat.
return;
}
} }
//can return earlier in some cases if(sp->getTargetType() == CSpell::LOCATION)
LOCPLINT->cb->castSpell(h, spell); {
adventureInt->enterCastingMode(sp);
return;
}
else if(sp->getTargetType() == CSpell::NO_TARGET)
{
LOCPLINT->cb->castSpell(h, mySpell);
}
else
{
logGlobal->error("Invalid spell target type");
}
} }
} }
} }