From 844d170b4f04b6c4c4a8d9e0e377c7aedd5e0b78 Mon Sep 17 00:00:00 2001 From: mateuszb Date: Wed, 4 Aug 2010 13:41:01 +0000 Subject: [PATCH] * Town portal implemented --- client/CSpellWindow.cpp | 49 +++++++++++++++++++++++++++++++++++++++++ client/CSpellWindow.h | 2 ++ server/CGameHandler.cpp | 10 ++++++++- 3 files changed, 60 insertions(+), 1 deletion(-) diff --git a/client/CSpellWindow.cpp b/client/CSpellWindow.cpp index 636f8567d..81fe8325b 100644 --- a/client/CSpellWindow.cpp +++ b/client/CSpellWindow.cpp @@ -570,6 +570,12 @@ Uint8 CSpellWindow::pagesWithinCurrentTab() return battleSpellsOnly ? sitesPerTabBattle[selectedTab] : sitesPerTabAdv[selectedTab]; } +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()); +} + CSpellWindow::SpellArea::SpellArea(SDL_Rect pos, CSpellWindow * owner) { this->pos = pos; @@ -639,12 +645,55 @@ void CSpellWindow::SpellArea::clickLeft(tribool down, bool previousState) case VIEW_AIR: case FLY: case WATER_WALK: + break; case TOWN_PORTAL: + { + std::vector availableTowns; + std::vector Towns = LOCPLINT->cb->getTownsInfo(false); + for(size_t i=0;ivisitingHero == NULL) //empty town and this is + { + availableTowns.push_back(t->id);//add to the list + } + } + + if (h->getSpellSchoolLevel(&CGI->spellh->spells[spell]) < 3) //not expert - teleport to nearest available city + { + int nearest = -1; //nearest town's ID + double dist = -1; + for (int g=0; gcb->getTownInfo(availableTowns[g], 1); + double curDist = dest->pos.dist2d(h->pos); + if (nearest == -1 || curDist < dist) + { + nearest = g; + dist = curDist; + } + } + + LOCPLINT->cb->castSpell(h, spell, + LOCPLINT->cb->getTownInfo(availableTowns[nearest], 1)->visitablePos() + h->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))); + } + + + return; + } break; default: assert(0); } + //can return earlier in some cases LOCPLINT->cb->castSpell(h, spell); } } diff --git a/client/CSpellWindow.h b/client/CSpellWindow.h index 0b0459bd3..81c00c9fc 100644 --- a/client/CSpellWindow.h +++ b/client/CSpellWindow.h @@ -109,6 +109,8 @@ public: void activate(); void deactivate(); void showAll(SDL_Surface * to); + + void teleportTo(int town, const CGHeroInstance * hero); }; #endif // __CSPELLWINDOW_H__ diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index d72b9543f..39cd91b4c 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -4919,13 +4919,21 @@ bool CGameHandler::castSpell(const CGHeroInstance *h, int spellID, const int3 &p sendAndApply(&gb); } break; + + case TOWN_PORTAL: //Town Portal + { + //TODO: check if given position is valid + moveHero(h->id,pos,1); + } + break; + case VISIONS: //Visions case VIEW_EARTH: //View Earth case DISGUISE: //Disguise case VIEW_AIR: //View Air - case TOWN_PORTAL: //Town Portal default: COMPLAIN_RET("This spell is not implemented yet!"); + break; } SetMana sm;