1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-07-15 01:24:45 +02:00

- some minor fixes: #626 #597 #275

- fixed console on Linux
This commit is contained in:
Ivan Savenko
2011-01-15 17:30:46 +00:00
parent b8f65697ca
commit 77ba5a5cd6
9 changed files with 91 additions and 37 deletions

View File

@ -578,7 +578,7 @@ Uint8 CSpellWindow::pagesWithinCurrentTab()
void CSpellWindow::teleportTo( int town, const CGHeroInstance * hero )
{
const CGTownInstance * dest = LOCPLINT->cb->getTownInfo(town, 1);
LOCPLINT->cb->castSpell(hero, Spells::TOWN_PORTAL, dest->visitablePos() + hero->getVisitableOffset());
LOCPLINT->cb->castSpell(hero, Spells::TOWN_PORTAL, dest->visitablePos());
}
CSpellWindow::SpellArea::SpellArea(SDL_Rect pos, CSpellWindow * owner)
@ -654,23 +654,20 @@ void CSpellWindow::SpellArea::clickLeft(tribool down, bool previousState)
case TOWN_PORTAL:
{
std::vector <int> availableTowns;
std::vector <const CGTownInstance*> Towns = LOCPLINT->cb->getTownsInfo(false);
for(size_t i=0;i<Towns.size();i++)
std::vector <const CGTownInstance*> Towns = LOCPLINT->cb->getTownsInfo(true);
if (Towns.empty())
{
const CGTownInstance *t = Towns[i];
if (t->visitingHero == NULL) //empty town and this is
{
availableTowns.push_back(t->id);//add to the list
}
LOCPLINT->showInfoDialog(CGI->generaltexth->allTexts[124]);
return;
}
if (h->getSpellSchoolLevel(&CGI->spellh->spells[spell]) < 3) //not expert - teleport to nearest available city
if (h->getSpellSchoolLevel(&CGI->spellh->spells[spell]) < 2) //not advanced or expert - teleport to nearest available city
{
int nearest = -1; //nearest town's ID
double dist = -1;
for (int g=0; g<availableTowns.size(); ++g)
for (int g=0; g<Towns.size(); ++g)
{
const CGTownInstance * dest = LOCPLINT->cb->getTownInfo(availableTowns[g], 1);
const CGTownInstance * dest = LOCPLINT->cb->getTownInfo(Towns[g]->id, 1);
double curDist = dest->pos.dist2d(h->pos);
if (nearest == -1 || curDist < dist)
{
@ -678,19 +675,32 @@ void CSpellWindow::SpellArea::clickLeft(tribool down, bool previousState)
dist = curDist;
}
}
LOCPLINT->cb->castSpell(h, spell,
LOCPLINT->cb->getTownInfo(availableTowns[nearest], 1)->visitablePos() + h->getVisitableOffset());
if ( Towns[nearest]->visitingHero )
LOCPLINT->showInfoDialog(CGI->generaltexth->allTexts[123]);
else
{
const CGTownInstance * town = LOCPLINT->cb->getTownInfo(Towns[nearest]->id, 1);
LOCPLINT->cb->castSpell(h, spell, town->visitablePos());// - town->getVisitableOffset());
}
}
else
{ //let the player choose
GH.pushInt (new CObjectListWindow(availableTowns,
new CPicture(graphics->spellscr->ourImages[spell].bitmap, 0, 0, false),
CGI->generaltexth->jktexts[40], CGI->generaltexth->jktexts[41],
boost::bind (&CSpellWindow::teleportTo, owner, _1, h)));
for(size_t i=0;i<Towns.size();i++)
{
const CGTownInstance *t = Towns[i];
if (t->visitingHero == NULL) //empty town and this is
{
availableTowns.push_back(t->id);//add to the list
}
}
if (availableTowns.empty())
LOCPLINT->showInfoDialog(CGI->generaltexth->allTexts[124]);
else
GH.pushInt (new CObjectListWindow(availableTowns,
new CPicture(graphics->spellscr->ourImages[spell].bitmap, 0, 0, false),
CGI->generaltexth->jktexts[40], CGI->generaltexth->jktexts[41],
boost::bind (&CSpellWindow::teleportTo, owner, _1, h)));
}
return;
}
break;