1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

* partial support for grail digging

This commit is contained in:
mateuszb 2010-02-21 15:03:30 +00:00
parent e6f31b7500
commit b2aa0e5930
13 changed files with 122 additions and 11 deletions

View File

@ -936,6 +936,13 @@ int3 CCallback::getGrailPos( float &outKnownRatio )
return gs->map->grailPos; return gs->map->grailPos;
} }
void CCallback::dig( const CGObjectInstance *hero )
{
DigWithHero dwh;
dwh.id = hero->id;
sendRequest(&dwh);
}
InfoAboutTown::InfoAboutTown() InfoAboutTown::InfoAboutTown()
{ {
tType = NULL; tType = NULL;

View File

@ -127,6 +127,7 @@ public:
virtual bool getPath2(int3 dest, CGPath &ret)=0; //uses main, client pathfinder info virtual bool getPath2(int3 dest, CGPath &ret)=0; //uses main, client pathfinder info
virtual void calculatePaths(const CGHeroInstance *hero, CPathsInfo &out, int3 src = int3(-1,-1,-1), int movement = -1) =0; virtual void calculatePaths(const CGHeroInstance *hero, CPathsInfo &out, int3 src = int3(-1,-1,-1), int movement = -1) =0;
virtual void recalculatePaths()=0; //updates main, client pathfinder info (should be called when moving hero is over) virtual void recalculatePaths()=0; //updates main, client pathfinder info (should be called when moving hero is over)
virtual void dig(const CGObjectInstance *hero)=0;
//map //map
virtual std::vector < const CGObjectInstance * > getBlockingObjs(int3 pos)const =0; virtual std::vector < const CGObjectInstance * > getBlockingObjs(int3 pos)const =0;
@ -223,6 +224,7 @@ public:
void save(const std::string &fname); void save(const std::string &fname);
void sendMessage(const std::string &mess); void sendMessage(const std::string &mess);
void buildBoat(const IShipyard *obj); void buildBoat(const IShipyard *obj);
void dig(const CGObjectInstance *hero);
//get info //get info
bool verifyPath(CPath * path, bool blockSea) const; bool verifyPath(CPath * path, bool blockSea) const;

View File

@ -578,7 +578,9 @@ void CTerrainRect::clickRight(tribool down, bool previousState)
const TerrainTile * tile = LOCPLINT->cb->getTileInfo(mp); const TerrainTile * tile = LOCPLINT->cb->getTileInfo(mp);
if (tile) if (tile)
{ {
CSimpleWindow * temp = CMessage::genWindow(VLC->generaltexth->terrainNames[tile->tertype], LOCPLINT->playerID, true); std::string hlp;
CGI->mh->getTerrainDescr(mp, hlp, true);
CSimpleWindow * temp = CMessage::genWindow(hlp, LOCPLINT->playerID, true);
CRClickPopupInt *rcpi = new CRClickPopupInt(temp,true); CRClickPopupInt *rcpi = new CRClickPopupInt(temp,true);
GH.pushInt(rcpi); GH.pushInt(rcpi);
} }
@ -706,7 +708,10 @@ void CTerrainRect::mouseMoved (const SDL_MouseMotionEvent & sEvent)
} }
else else
{ {
adventureInt->statusbar.clear(); std::string hlp;
CGI->mh->getTerrainDescr(pom, hlp, false);
adventureInt->statusbar.print(hlp);
//adventureInt->statusbar.clear();
} }
const CGPathNode *pnode = LOCPLINT->cb->getPathInfo(pom); const CGPathNode *pnode = LOCPLINT->cb->getPathInfo(pom);

View File

@ -2064,8 +2064,8 @@ CHotSeatPlayers::CHotSeatPlayers(const std::string &firstPlayer)
txt[0]->setText(firstPlayer); txt[0]->setText(firstPlayer);
txt[0]->giveFocus(); txt[0]->giveFocus();
ok = new AdventureMapButton(CGI->generaltexth->zelp[560], bind(&CHotSeatPlayers::enterSelectionScreen, this), 95, 338, "MUBCHCK.DEF"); ok = new AdventureMapButton(CGI->generaltexth->zelp[560], bind(&CHotSeatPlayers::enterSelectionScreen, this), 95, 338, "MUBCHCK.DEF", SDLK_RETURN);
cancel = new AdventureMapButton(CGI->generaltexth->zelp[561], bind(&CGuiHandler::popIntTotally, ref(GH), this), 205, 338, "MUBCANC.DEF"); cancel = new AdventureMapButton(CGI->generaltexth->zelp[561], bind(&CGuiHandler::popIntTotally, ref(GH), this), 205, 338, "MUBCANC.DEF", SDLK_ESCAPE);
bar = new CGStatusBar(new CPicture(Rect(7, 381, 348, 18), 0));//226, 472 bar = new CGStatusBar(new CPicture(Rect(7, 381, 348, 18), 0));//226, 472
} }
@ -2313,6 +2313,10 @@ CBonusSelection::CRegion::~CRegion()
void CBonusSelection::CRegion::clickLeft( tribool down, bool previousState ) void CBonusSelection::CRegion::clickLeft( tribool down, bool previousState )
{ {
//select if selectable & clicked inside our graphic //select if selectable & clicked inside our graphic
if ( indeterminate(down) )
{
return;
}
if( !down && selectable && !CSDL_Ext::isTransparent(graphics[0], GH.current->motion.x-pos.x, GH.current->motion.y-pos.y) ) if( !down && selectable && !CSDL_Ext::isTransparent(graphics[0], GH.current->motion.x-pos.x, GH.current->motion.y-pos.y) )
{ {
owner->selectMap(myNumber); owner->selectMap(myNumber);

View File

@ -116,6 +116,17 @@ void CDefObjInfoHandler::load()
if(nobj->id==TOWNI_TYPE) if(nobj->id==TOWNI_TYPE)
castles[nobj->subid]=nobj; castles[nobj->subid]=nobj;
} }
for (int i = 0; i < 8 ; i++)
{
static const char *holeDefs[] = {"AVLHOLD0.DEF", "AVLHLDS0.DEF", "AVLHOLG0.DEF", "AVLHLSN0.DEF",
"AVLHOLS0.DEF", "AVLHOLR0.DEF", "AVLHOLX0.DEF", "AVLHOLL0.DEF"};
CGDefInfo * tmp = gobjs[124][0];
gobjs[124][i] = gobjs[124][0];
gobjs[124][i]->name = holeDefs[i];
}
} }
CDefObjInfoHandler::~CDefObjInfoHandler() CDefObjInfoHandler::~CDefObjInfoHandler()

View File

@ -1411,6 +1411,18 @@ struct MakeCustomAction : public CPackForServer
} }
}; };
struct DigWithHero : public CPackForServer
{
DigWithHero(){}
si32 id; //digging hero id
bool applyGh(CGameHandler *gh);
template <typename Handler> void serialize(Handler &h, const int version)
{
h & id;
}
};
/***********************************************************************************************************/ /***********************************************************************************************************/
struct SaveGame : public CPackForClient, public CPackForServer struct SaveGame : public CPackForClient, public CPackForServer

View File

@ -574,6 +574,13 @@ DLL_EXPORT void NewObject::applyGs( CGameState *gs )
id = o->id = gs->map->objects.size(); id = o->id = gs->map->objects.size();
o->hoverName = VLC->generaltexth->names[ID]; o->hoverName = VLC->generaltexth->names[ID];
if(ID == 124) // hole
{
const TerrainTile &t = gs->map->getTile(pos);
o->defInfo = VLC->dobjinfo->gobjs[ID][t.tertype];
assert(o->defInfo);
}
gs->map->objects.push_back(o); gs->map->objects.push_back(o);
gs->map->addBlockVisTiles(o); gs->map->addBlockVisTiles(o);
o->initObj(); o->initObj();

View File

@ -1264,7 +1264,7 @@ void Mapa::readTerrain( const unsigned char * bufor, int &i)
void Mapa::readDefInfo( const unsigned char * bufor, int &i) void Mapa::readDefInfo( const unsigned char * bufor, int &i)
{ {
int defAmount = readNormalNr(bufor,i); i+=4; int defAmount = readNormalNr(bufor,i); i+=4;
defy.reserve(defAmount); defy.reserve(defAmount+8);
for (int idd = 0 ; idd<defAmount; idd++) // reading defs for (int idd = 0 ; idd<defAmount; idd++) // reading defs
{ {
CGDefInfo * vinya = new CGDefInfo(); // info about new def CGDefInfo * vinya = new CGDefInfo(); // info about new def
@ -1334,6 +1334,12 @@ void Mapa::readDefInfo( const unsigned char * bufor, int &i)
defy.push_back(vinya); // add this def to the vector defy.push_back(vinya); // add this def to the vector
} }
//add holes - they always can appear
for (int i = 0; i < 8 ; i++)
{
defy.push_back(VLC->dobjinfo->gobjs[124][i]);
}
} }
void Mapa::readObjects( const unsigned char * bufor, int &i) void Mapa::readObjects( const unsigned char * bufor, int &i)

View File

@ -17,6 +17,7 @@
#include "hch/CDefHandler.h" #include "hch/CDefHandler.h"
#include "client/CConfigHandler.h" #include "client/CConfigHandler.h"
#include <boost/assign/list_of.hpp> #include <boost/assign/list_of.hpp>
#include "hch/CGeneralTextHandler.h"
/* /*
* mapHandler.cpp, part of VCMI engine * mapHandler.cpp, part of VCMI engine
@ -308,7 +309,14 @@ static void processDef (CGDefInfo* def)
{ {
if(def->name.size()) if(def->name.size())
{ {
def->handler = CDefHandler::giveDefEss(def->name); if(vstd::contains(CGI->mh->loadedDefs, def->name))
{
def->handler = CGI->mh->loadedDefs[def->name];
}
else
{
CGI->mh->loadedDefs[def->name] = def->handler = CDefHandler::giveDefEss(def->name);
}
} }
else else
{ {
@ -316,9 +324,11 @@ static void processDef (CGDefInfo* def)
def->handler = NULL; def->handler = NULL;
return; return;
} }
def->width = def->handler->ourImages[0].bitmap->w/32; def->width = def->handler->ourImages[0].bitmap->w/32;
def->height = def->handler->ourImages[0].bitmap->h/32; def->height = def->handler->ourImages[0].bitmap->h/32;
} }
CGDefInfo* pom = CGI->dobjinfo->gobjs[def->id][def->subid]; CGDefInfo* pom = CGI->dobjinfo->gobjs[def->id][def->subid];
if(pom && def->id!=TOWNI_TYPE) if(pom && def->id!=TOWNI_TYPE)
{ {
@ -417,16 +427,20 @@ void CMapHandler::init()
for(size_t h=0; h<map->defy.size(); ++h) //initializing loaded def handler's info {
CGI->mh->loadedDefs.insert(std::make_pair(map->defy[h]->name, map->defy[h]->handler));
tlog0<<"\tCollecting loaded def's handlers: "<<th.getDif()<<std::endl;
prepareFOWDefs(); prepareFOWDefs();
roadsRiverTerrainInit(); //road's and river's DefHandlers; and simple values initialization roadsRiverTerrainInit(); //road's and river's DefHandlers; and simple values initialization
borderAndTerrainBitmapInit(); borderAndTerrainBitmapInit();
tlog0<<"\tPreparing FoW, roads, rivers,borders: "<<th.getDif()<<std::endl; tlog0<<"\tPreparing FoW, roads, rivers,borders: "<<th.getDif()<<std::endl;
initObjectRects(); initObjectRects();
tlog0<<"\tMaking object rects: "<<th.getDif()<<std::endl; tlog0<<"\tMaking object rects: "<<th.getDif()<<std::endl;
for (int i = 0; i < 8 ; i++)
{
TerrainTile2 &t = ttiles[24+i][0][0];
tlog0 << t.objects.front().first->defInfo->name << ' ';
}
} }
// Update map window screen // Update map window screen
@ -1324,6 +1338,23 @@ CMapHandler::CMapHandler()
partialHide = NULL; partialHide = NULL;
} }
void CMapHandler::getTerrainDescr( const int3 &pos, std::string & out, bool terName )
{
out.clear();
TerrainTile2 &t = ttiles[pos.x][pos.y][pos.z];
for(std::vector < std::pair<const CGObjectInstance*,SDL_Rect> >::const_iterator i = t.objects.begin(); i != t.objects.end(); i++)
{
if(i->first->ID == 124)
{
out = i->first->hoverName;
return;
}
}
if(terName)
out = CGI->generaltexth->terrainNames[t.tileInfo->tertype];
}
TerrainTile2::TerrainTile2() TerrainTile2::TerrainTile2()
:tileInfo(0),terbitmap(0) :tileInfo(0),terbitmap(0)
{} {}

View File

@ -114,10 +114,10 @@ public:
CMapHandler(); //c-tor CMapHandler(); //c-tor
~CMapHandler(); //d-tor ~CMapHandler(); //d-tor
void loadDefs();
SDL_Surface * getVisBitmap(int x, int y, const std::vector< std::vector< std::vector<unsigned char> > > & visibilityMap, int lvl); SDL_Surface * getVisBitmap(int x, int y, const std::vector< std::vector< std::vector<unsigned char> > > & visibilityMap, int lvl);
std::vector< std::string > getObjDescriptions(int3 pos); //returns desriptions of objects blocking given position std::vector< std::string > getObjDescriptions(int3 pos); //returns desriptions of objects blocking given position
void getTerrainDescr(const int3 &pos, std::string & out, bool terName); //if tername == false => empty string when tile is clear
CGObjectInstance * createObject(int id, int subid, int3 pos, int owner=254); //creates a new object with a certain id and subid CGObjectInstance * createObject(int id, int subid, int3 pos, int owner=254); //creates a new object with a certain id and subid
bool printObject(const CGObjectInstance * obj); //puts appropriate things to ttiles, so obj will be visible on map bool printObject(const CGObjectInstance * obj); //puts appropriate things to ttiles, so obj will be visible on map
bool hideObject(const CGObjectInstance * obj); //removes appropriate things from ttiles, so obj will be no longer visible on map (but still will exist) bool hideObject(const CGObjectInstance * obj); //removes appropriate things from ttiles, so obj will be no longer visible on map (but still will exist)

View File

@ -3886,3 +3886,22 @@ void CGameHandler::getLossVicMessage( ui8 player, ui8 standard, bool victory, In
} }
} }
} }
bool CGameHandler::dig( const CGHeroInstance *h )
{
for (std::vector<CGObjectInstance*>::const_iterator i = gs->map->objects.begin(); i != gs->map->objects.end(); i++) //unflag objs
{
if((*i)->ID == 124 && (*i)->pos == h->getPosition(false))
{
complain("Cannot dig - there is already a hole under the hero!");
return false;
}
}
NewObject no;
no.ID = 124;
no.pos = h->getPosition(false);
no.subID = 0;
sendAndApply(&no);
return true;
}

View File

@ -179,6 +179,7 @@ public:
bool complain(const std::string &problem); //sends message to all clients, prints on the logs and return true bool complain(const std::string &problem); //sends message to all clients, prints on the logs and return true
void objectVisited( const CGObjectInstance * obj, const CGHeroInstance * h ); void objectVisited( const CGObjectInstance * obj, const CGHeroInstance * h );
void engageIntoBattle( ui8 player ); void engageIntoBattle( ui8 player );
bool dig(const CGHeroInstance *h);
template <typename Handler> void serialize(Handler &h, const int version) template <typename Handler> void serialize(Handler &h, const int version)
{ {

View File

@ -154,6 +154,12 @@ bool MakeCustomAction::applyGh( CGameHandler *gh )
return gh->makeCustomAction(ba); return gh->makeCustomAction(ba);
} }
bool DigWithHero::applyGh( CGameHandler *gh )
{
ERROR_IF_NOT_OWNS(id);
return gh->dig(gh->getHero(id));
}
bool PlayerMessage::applyGh( CGameHandler *gh ) bool PlayerMessage::applyGh( CGameHandler *gh )
{ {
if(gh->getPlayerAt(c) != player) ERROR_AND_RETURN; if(gh->getPlayerAt(c) != player) ERROR_AND_RETURN;