1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-28 08:48:48 +02:00

Dismissing heroes / minor.

This commit is contained in:
Michał W. Urbańczyk 2008-08-01 21:41:38 +00:00
parent bfad10a8e4
commit 1f4b4364df
8 changed files with 55 additions and 30 deletions

View File

@ -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<ui8, PlayerState>::iterator i=gs->players.begin() ; i!=gs->players.end();i++)
std::vector < const CGHeroInstance *> ret;
for(int i=0;i<gs->map->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<int, PlayerState>::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<CGHeroInstance *>(hero);
CGI->mh->removeObject(Vhero);
std::vector<CGHeroInstance*>::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()

View File

@ -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"));

View File

@ -135,6 +135,18 @@ void CGameState::apply(IPack * pack)
players[sr->player].resources[i] = sr->res[i];
break;
}
case 500:
{
RemoveHero *rh = static_cast<RemoveHero*>(pack);
CGHeroInstance *h = static_cast<CGHeroInstance*>(map->objects[rh->id]);
std::vector<CGHeroInstance*>::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<TryMoveHero*>(pack);

View File

@ -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<boost::mutex> 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<boost::mutex> 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)

View File

@ -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<CGHeroInstance*>(gs->map->objects[rh.id]);
std::cout << "Removing hero with id = "<<(unsigned)rh.id<<std::endl;
CGI->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

View File

@ -82,6 +82,17 @@ struct SetResources : public CPack<SetResources> //104
h & player & res;
}
};
struct RemoveHero : public CPack<RemoveHero> //500
{
RemoveHero(){type = 500;};
RemoveHero(si32 ID){id = ID;type = 500;};
si32 id;
template <typename Handler> void serialize(Handler &h, const int version)
{
h & id;
}
};
struct TryMoveHero : public CPack<TryMoveHero> //501
{
TryMoveHero(){type = 501;};

View File

@ -1158,10 +1158,7 @@ bool CMapHandler::hideObject(CGObjectInstance *obj)
bool CMapHandler::removeObject(CGObjectInstance *obj)
{
hideObject(obj);
std::vector<CGObjectInstance *>::iterator db = std::find(map->objects.begin(), map->objects.end(), obj);
recalculateHideVisPosUnderObj(*db);
delete *db;
map->objects.erase(db);
recalculateHideVisPosUnderObj(obj);
return true;
}

View File

@ -67,6 +67,14 @@ void CGameHandler::handleConnection(std::set<int> 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;