diff --git a/CCallback.cpp b/CCallback.cpp index bddd033b7..ec6b77f11 100644 --- a/CCallback.cpp +++ b/CCallback.cpp @@ -357,17 +357,15 @@ std::vector < const CGTownInstance *> CCallback::getTownsInfo(bool onlyOur) } std::vector < const CGHeroInstance *> CCallback::getHeroesInfo(bool onlyOur) { - std::vector < const CGHeroInstance *> ret = std::vector < const CGHeroInstance *>(); - for ( std::map::iterator i=gs->players.begin() ; i!=gs->players.end();i++) + std::vector < const CGHeroInstance *> ret; + for(int i=0;imap->heroes.size();i++) { - for (int j=0;j<(*i).second.heroes.size();j++) + if( (gs->map->heroes[i]->tempOwner==player) || + (isVisible(gs->map->heroes[i]->getPosition(false),player) && !onlyOur) ) { - if ( ( isVisible((*i).second.heroes[j]->getPosition(false),player) ) || (*i).first==player) - { - ret.push_back((*i).second.heroes[j]); - } + ret.push_back(gs->map->heroes[i]); } - } // for ( std::map::iterator i=gs->players.begin() ; i!=gs->players.end();i++) + } return ret; } @@ -430,12 +428,9 @@ int CCallback::splitStack(const CGObjectInstance *s1, const CGObjectInstance *s2 bool CCallback::dismissHero(const CGHeroInstance *hero) { - CGHeroInstance * Vhero = const_cast(hero); - CGI->mh->removeObject(Vhero); - std::vector::iterator nitr = find(CGI->state->players[player].heroes.begin(), CGI->state->players[player].heroes.end(), Vhero); - CGI->state->players[player].heroes.erase(nitr); - LOCPLINT->adventureInt->heroList.updateHList(); - return false; + if(player!=hero->tempOwner) return false; + *cl->serv << ui16(500) << hero->id; + return true; } int CCallback::getMySerial() diff --git a/CCursorHandler.cpp b/CCursorHandler.cpp index af3476d5b..5c17dc95d 100644 --- a/CCursorHandler.cpp +++ b/CCursorHandler.cpp @@ -9,17 +9,6 @@ extern SDL_Surface * screen; void CCursorHandler::initCursor() { -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - int rmask = 0xff000000; - int gmask = 0x00ff0000; - int bmask = 0x0000ff00; - int amask = 0x000000ff; -#else - int rmask = 0x000000ff; - int gmask = 0x0000ff00; - int bmask = 0x00ff0000; - int amask = 0xff000000; -#endif mode = number = xpos = ypos = 0; help = CSDL_Ext::newSurface(32,32); cursors.push_back(CDefHandler::giveDef("CRADVNTR.DEF")); diff --git a/CGameState.cpp b/CGameState.cpp index efcef9ad7..25e57b8d3 100644 --- a/CGameState.cpp +++ b/CGameState.cpp @@ -135,6 +135,18 @@ void CGameState::apply(IPack * pack) players[sr->player].resources[i] = sr->res[i]; break; } + case 500: + { + RemoveHero *rh = static_cast(pack); + CGHeroInstance *h = static_cast(map->objects[rh->id]); + std::vector::iterator nitr = std::find(map->heroes.begin(), map->heroes.end(),h); + map->heroes.erase(nitr); + int player = h->tempOwner; + nitr = std::find(players[player].heroes.begin(), players[player].heroes.end(), h); + players[player].heroes.erase(nitr); + map->objects[h->id] = NULL; + break; + } case 501://hero try-move { TryMoveHero * n = static_cast(pack); diff --git a/CPlayerInterface.cpp b/CPlayerInterface.cpp index 6adcb350b..b5bf15f42 100644 --- a/CPlayerInterface.cpp +++ b/CPlayerInterface.cpp @@ -6,7 +6,6 @@ #include "mapHandler.h" #include "SDL_Extensions.h" #include "SDL_framerate.h" -#include "CScreenHandler.h" #include "CCursorHandler.h" #include "CCallback.h" #include "SDL_Extensions.h" @@ -1569,7 +1568,9 @@ void CPlayerInterface::heroMoved(const HeroMoveDetails & details) } void CPlayerInterface::heroKilled(const CGHeroInstance* hero) { + boost::unique_lock un(*pim); graphics->heroWins.erase(hero->ID); + adventureInt->heroList.updateHList(); } void CPlayerInterface::heroCreated(const CGHeroInstance * hero) { @@ -1850,6 +1851,7 @@ int3 CPlayerInterface::repairScreenPos(int3 pos) } void CPlayerInterface::heroPrimarySkillChanged(const CGHeroInstance * hero, int which, int val) { + boost::unique_lock un(*pim); SDL_FreeSurface(graphics->heroWins[hero->subID]);//TODO: moznaby zmieniac jedynie fragment bitmapy zwiazany z dana umiejetnoscia graphics->heroWins[hero->subID] = infoWin(hero); //a nie przerysowywac calosc. Troche roboty, obecnie chyba nie wartej swieczki. if (adventureInt->selection.selected == hero) diff --git a/client/Client.cpp b/client/Client.cpp index b2642cd2e..d68db84ec 100644 --- a/client/Client.cpp +++ b/client/Client.cpp @@ -200,6 +200,17 @@ void CClient::process(int what) playerint[sr.player]->receivedResource(-1,-1); break; } + case 500: + { + RemoveHero rh; + *serv >> rh; + CGHeroInstance *h = static_cast(gs->map->objects[rh.id]); + std::cout << "Removing hero with id = "<<(unsigned)rh.id<mh->removeObject(h); + gs->apply(&rh); + playerint[h->tempOwner]->heroKilled(h); + break; + } case 501: //hero movement response - we have to notify interfaces and callback { TryMoveHero *th = new TryMoveHero; //will be deleted by callback after processing diff --git a/lib/NetPacks.h b/lib/NetPacks.h index 257d20b9d..9b3a2c410 100644 --- a/lib/NetPacks.h +++ b/lib/NetPacks.h @@ -82,6 +82,17 @@ struct SetResources : public CPack //104 h & player & res; } }; +struct RemoveHero : public CPack //500 +{ + RemoveHero(){type = 500;}; + RemoveHero(si32 ID){id = ID;type = 500;}; + si32 id; + + template void serialize(Handler &h, const int version) + { + h & id; + } +}; struct TryMoveHero : public CPack //501 { TryMoveHero(){type = 501;}; diff --git a/mapHandler.cpp b/mapHandler.cpp index 03e830685..8bc13b20d 100644 --- a/mapHandler.cpp +++ b/mapHandler.cpp @@ -1158,10 +1158,7 @@ bool CMapHandler::hideObject(CGObjectInstance *obj) bool CMapHandler::removeObject(CGObjectInstance *obj) { hideObject(obj); - std::vector::iterator db = std::find(map->objects.begin(), map->objects.end(), obj); - recalculateHideVisPosUnderObj(*db); - delete *db; - map->objects.erase(db); + recalculateHideVisPosUnderObj(obj); return true; } diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index 312ba1792..602c5acb3 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -67,6 +67,14 @@ void CGameHandler::handleConnection(std::set players, CConnection &c) cTurn.notify_all(); break; } + case 500: + { + si32 id; + c >> id; + RemoveHero rh(id); + sendAndApply(&rh); + break; + } case 501://interface wants to move hero { int3 start, end;