From 9aa6d0a7b9abb00a266bf92a89910fafd510a247 Mon Sep 17 00:00:00 2001 From: mateuszb Date: Mon, 16 Aug 2010 13:51:31 +0000 Subject: [PATCH] * refactoring of map handler and minor changes --- CCallback.cpp | 14 +- client/CGameInfo.h | 15 +- client/CPlayerInterface.cpp | 12 +- client/Client.cpp | 28 +++ client/Graphics.h | 3 + client/mapHandler.cpp | 437 ++++++++++-------------------------- client/mapHandler.h | 20 +- hch/CObjectHandler.h | 30 +++ lib/map.cpp | 62 +---- lib/map.h | 38 +--- 10 files changed, 201 insertions(+), 458 deletions(-) diff --git a/CCallback.cpp b/CCallback.cpp index 537be9146..9e85282d5 100644 --- a/CCallback.cpp +++ b/CCallback.cpp @@ -283,8 +283,8 @@ bool CCallback::verifyPath(CPath * path, bool blockSea) const { for (size_t i=0; i < path->nodes.size(); ++i) { - if ( CGI->mh->ttiles[path->nodes[i].coord.x][path->nodes[i].coord.y][path->nodes[i].coord.z].tileInfo->blocked - && (! (CGI->mh->ttiles[path->nodes[i].coord.x][path->nodes[i].coord.y][path->nodes[i].coord.z].tileInfo->visitable))) + if ( CGI->mh->map->terrain[path->nodes[i].coord.x][path->nodes[i].coord.y][path->nodes[i].coord.z].blocked + && (! (CGI->mh->map->terrain[path->nodes[i].coord.x][path->nodes[i].coord.y][path->nodes[i].coord.z].visitable))) return false; //path is wrong - one of the tiles is blocked if (blockSea) @@ -293,15 +293,15 @@ bool CCallback::verifyPath(CPath * path, bool blockSea) const continue; if ( - ((CGI->mh->ttiles[path->nodes[i].coord.x][path->nodes[i].coord.y][path->nodes[i].coord.z].tileInfo->tertype==TerrainTile::water) + ((CGI->mh->map->terrain[path->nodes[i].coord.x][path->nodes[i].coord.y][path->nodes[i].coord.z].tertype==TerrainTile::water) && - (CGI->mh->ttiles[path->nodes[i-1].coord.x][path->nodes[i-1].coord.y][path->nodes[i-1].coord.z].tileInfo->tertype!=TerrainTile::water)) + (CGI->mh->map->terrain[path->nodes[i-1].coord.x][path->nodes[i-1].coord.y][path->nodes[i-1].coord.z].tertype!=TerrainTile::water)) || - ((CGI->mh->ttiles[path->nodes[i].coord.x][path->nodes[i].coord.y][path->nodes[i].coord.z].tileInfo->tertype!=TerrainTile::water) + ((CGI->mh->map->terrain[path->nodes[i].coord.x][path->nodes[i].coord.y][path->nodes[i].coord.z].tertype!=TerrainTile::water) && - (CGI->mh->ttiles[path->nodes[i-1].coord.x][path->nodes[i-1].coord.y][path->nodes[i-1].coord.z].tileInfo->tertype==TerrainTile::water)) + (CGI->mh->map->terrain[path->nodes[i-1].coord.x][path->nodes[i-1].coord.y][path->nodes[i-1].coord.z].tertype==TerrainTile::water)) || - (CGI->mh->ttiles[path->nodes[i-1].coord.x][path->nodes[i-1].coord.y][path->nodes[i-1].coord.z].tileInfo->tertype==TerrainTile::rock) + (CGI->mh->map->terrain[path->nodes[i-1].coord.x][path->nodes[i-1].coord.y][path->nodes[i-1].coord.z].tertype==TerrainTile::rock) ) return false; diff --git a/client/CGameInfo.h b/client/CGameInfo.h index 973b65901..a0636e025 100644 --- a/client/CGameInfo.h +++ b/client/CGameInfo.h @@ -17,29 +17,21 @@ class CMapHandler; class CArtHandler; class CHeroHandler; class CCreatureHandler; -class CAbilityHandler; class CSpellHandler; -class CAmbarCendamo; -class CPreGameTextHandler; class CBuildingHandler; class CObjectHandler; class CSoundHandler; class CMusicHandler; class CDefObjInfoHandler; class CTownHandler; -class CLodHandler; class CGeneralTextHandler; class CConsoleHandler; -class CPathfinder; class CCursorHandler; -class CScreenHandler; class CGameState; -class CMapHandler; -class CGameInterface; -class CPreGame; -class CDefHandler; class CVideoPlayer; +class Mapa; + /* CGameInfo class for allowing different functions for accessing game informations @@ -62,13 +54,12 @@ public: /*const*/ CGeneralTextHandler * generaltexth; CConsoleHandler * consoleh; CCursorHandler * curh; - /*const*/ CScreenHandler * screenh; CVideoPlayer * videoh; void setFromLib(); friend class CClient; - friend class CMapHandler; //TODO: remove it + friend void initVillagesCapitols(Mapa * map); CGameInfo(); }; diff --git a/client/CPlayerInterface.cpp b/client/CPlayerInterface.cpp index fb45386d4..86980fd5e 100644 --- a/client/CPlayerInterface.cpp +++ b/client/CPlayerInterface.cpp @@ -206,7 +206,7 @@ void CPlayerInterface::yourTurn() acceptTurn(); } -inline void subRect(const int & x, const int & y, const int & z, const SDL_Rect & r, const int & hid) +STRONG_INLINE void subRect(const int & x, const int & y, const int & z, const SDL_Rect & r, const int & hid) { TerrainTile2 & hlp = CGI->mh->ttiles[x][y][z]; for(int h=0; hmh->ttiles[x][y][z]; for(int h=0; hmh->frameW; if(pos.y<-CGI->mh->frameH) pos.y = -CGI->mh->frameH; - if(pos.x>CGI->mh->map->width - adventureInt->terrain.tilesw + CGI->mh->frameW) - pos.x = CGI->mh->map->width - adventureInt->terrain.tilesw + CGI->mh->frameW; - if(pos.y>CGI->mh->map->height - adventureInt->terrain.tilesh + CGI->mh->frameH) - pos.y = CGI->mh->map->height - adventureInt->terrain.tilesh + CGI->mh->frameH; + if(pos.x>CGI->mh->sizes.x - adventureInt->terrain.tilesw + CGI->mh->frameW) + pos.x = CGI->mh->sizes.x - adventureInt->terrain.tilesw + CGI->mh->frameW; + if(pos.y>CGI->mh->sizes.y - adventureInt->terrain.tilesh + CGI->mh->frameH) + pos.y = CGI->mh->sizes.y - adventureInt->terrain.tilesh + CGI->mh->frameH; return pos; } void CPlayerInterface::heroPrimarySkillChanged(const CGHeroInstance * hero, int which, si64 val) diff --git a/client/Client.cpp b/client/Client.cpp index ab016e82f..b72f8e9ae 100644 --- a/client/Client.cpp +++ b/client/Client.cpp @@ -191,6 +191,31 @@ void CClient::save(const std::string & fname) *serv << &SaveGame(fname); } +#include +void initVillagesCapitols(Mapa * map) +{ + std::ifstream ifs(DATA_DIR "/config/townsDefs.txt"); + int ccc; + ifs>>ccc; + for(int i=0;istate->villages[i]; + map->defy.push_back(CGI->state->forts[i]); + } + else + n = CGI->state->capitols[i%ccc]; + + ifs >> n->name; + if(!n) + tlog1 << "*HUGE* Warning - missing town def for " << i << std::endl; + else + map->defy.push_back(n); + } +} + void CClient::endGame() { tlog0 << "\n\nEnding current game!" << std::endl; @@ -274,6 +299,8 @@ void CClient::loadGame( const std::string & fname ) CGI->mh->map = gs->map; pathInfo = new CPathsInfo(int3(gs->map->width, gs->map->height, gs->map->twoLevel+1)); CGI->mh->init(); + initVillagesCapitols(gs->map); + tlog0 <<"Initing maphandler: "<mh->map = gs->map; tlog0 <<"Creating mapHandler: "<mh->init(); + initVillagesCapitols(gs->map); pathInfo = new CPathsInfo(int3(gs->map->width, gs->map->height, gs->map->twoLevel+1)); tlog0 <<"Initializing mapHandler (together): "< heroAnims; // [class id: 0 - 17] //added group 10: up - left, 11 - left and 12 - left down // 13 - up-left standing; 14 - left standing; 15 - left down standing std::vector boatAnims; // [boat type: 0 - 3] //added group 10: up - left, 11 - left and 12 - left down // 13 - up-left standing; 14 - left standing; 15 - left down standing + std::map mapObjectDefs; //pointers to loaded defs (key is filename, uppercase) + CDefHandler * FoWfullHide; //for Fog of War + CDefHandler * FoWpartialHide; //for For of War //creatures std::map smallImgs; //creature ID -> small 32x32 img of creature; //ID=-2 is for blank (black) img; -1 for the border std::map bigImgs; //creature ID -> big 58x64 img of creature; //ID=-2 is for blank (black) img; -1 for the border diff --git a/client/mapHandler.cpp b/client/mapHandler.cpp index 6ea654982..6e3898787 100644 --- a/client/mapHandler.cpp +++ b/client/mapHandler.cpp @@ -84,51 +84,51 @@ struct OCM_HLP } } ocmptwo ; -void alphaTransformDef(CGDefInfo * defInfo) -{ - for(int yy=0; yyhandler->ourImages.size(); ++yy) - { - CSDL_Ext::alphaTransform(defInfo->handler->ourImages[yy].bitmap); - } -} +// void alphaTransformDef(CGDefInfo * defInfo) +// { +// for(int yy=0; yyhandler->ourImages.size(); ++yy) +// { +// CSDL_Ext::alphaTransform(defInfo->handler->ourImages[yy].bitmap); +// } +// } void CMapHandler::prepareFOWDefs() { - fullHide = CDefHandler::giveDef("TSHRC.DEF"); - partialHide = CDefHandler::giveDef("TSHRE.DEF"); + graphics->FoWfullHide = CDefHandler::giveDef("TSHRC.DEF"); + graphics->FoWpartialHide = CDefHandler::giveDef("TSHRE.DEF"); //adding necessary rotations - int missRot [] = {22, 15, 2, 13, 12, 16, 18, 17, 20, 19, 7, 24, 26, 25, 30, 32, 27, 28}; + static const int missRot [] = {22, 15, 2, 13, 12, 16, 18, 17, 20, 19, 7, 24, 26, 25, 30, 32, 27, 28}; Cimage nw; for(int g=0; gourImages[missRot[g]]; + nw = graphics->FoWpartialHide->ourImages[missRot[g]]; nw.bitmap = CSDL_Ext::rotate01(nw.bitmap); - partialHide->ourImages.push_back(nw); + graphics->FoWpartialHide->ourImages.push_back(nw); } //necessaary rotations added //alpha - transformation - for(size_t i=0; iourImages.size(); ++i) + for(size_t i=0; iFoWpartialHide->ourImages.size(); ++i) { - CSDL_Ext::alphaTransform(partialHide->ourImages[i].bitmap); + CSDL_Ext::alphaTransform(graphics->FoWpartialHide->ourImages[i].bitmap); } //initialization of type of full-hide image - hideBitmap.resize(CGI->mh->map->width); + hideBitmap.resize(sizes.x); for (size_t i=0;imh->map->height); + hideBitmap[i].resize(sizes.y); } for (size_t i=0; imh->map->height; ++j) + for (int j=0; j < sizes.y; ++j) { - hideBitmap[i][j].resize(CGI->mh->map->twoLevel+1); - for(int k=0; kmh->map->twoLevel+1; ++k) + hideBitmap[i][j].resize(sizes.z); + for(int k=0; kourImages.size(); + hideBitmap[i][j][k] = rand()%graphics->FoWfullHide->ourImages.size(); } } } @@ -160,32 +160,26 @@ void CMapHandler::roadsRiverTerrainInit() } } - sizes.x = CGI->mh->map->width; - sizes.y = CGI->mh->map->height; - sizes.z = CGI->mh->map->twoLevel+1; - // Create enough room for the whole map and its frame - ttiles.resize(CGI->mh->map->width, frameW, frameW); + ttiles.resize(sizes.x, frameW, frameW); for (int i=0-frameW;imh->map->height, frameH, frameH); + ttiles[i].resize(sizes.y, frameH, frameH); } for (int i=0-frameW;imh->map->height+frameH;j++) - ttiles[i][j].resize(CGI->mh->map->twoLevel+1, 0, 0); + for (int j=0-frameH;j<(int)sizes.y+frameH;j++) + ttiles[i][j].resize(sizes.z, 0, 0); } // prepare the map - for (int i=0; iwidth; i++) //by width + for (int i=0; iheight;j++) //by height + for (int j=0; jtwoLevel; ++k) //by levels + for (int k=0; kterrain[i][j][k]); } } } @@ -205,31 +199,31 @@ void CMapHandler::borderAndTerrainBitmapInit() delete hlp; } - for (int i=0-frameW; iwidth+frameW; i++) //by width + for (int i=0-frameW; iheight+frameH;j++) //by height + for (int j=0-frameH; jtwoLevel; ++k) //by levles + for(int k=0; k (map->width-1) || j < 0 || j > (map->height-1)) + if(i < 0 || i > (sizes.x-1) || j < 0 || j > (sizes.y-1)) { int terBitmapNum = -1; if(i==-1 && j==-1) terBitmapNum = 16; - else if(i==-1 && j==(map->height)) + else if(i==-1 && j==(sizes.y)) terBitmapNum = 19; - else if(i==(map->width) && j==-1) + else if(i==(sizes.x) && j==-1) terBitmapNum = 17; - else if(i==(map->width) && j==(map->height)) + else if(i==(sizes.x) && j==(sizes.y)) terBitmapNum = 18; - else if(j == -1 && i > -1 && i < map->height) + else if(j == -1 && i > -1 && i < sizes.y) terBitmapNum = 22+rand()%2; - else if(i == -1 && j > -1 && j < map->height) + else if(i == -1 && j > -1 && j < sizes.y) terBitmapNum = 33+rand()%2; - else if(j == map->height && i >-1 && i < map->width) + else if(j == sizes.y && i >-1 && i < sizes.x) terBitmapNum = 29+rand()%2; - else if(i == map->width && j > -1 && j < map->height) + else if(i == sizes.x && j > -1 && j < sizes.y) terBitmapNum = 25+rand()%2; else terBitmapNum = rand()%16; @@ -309,13 +303,13 @@ static void processDef (CGDefInfo* def) { if(def->name.size()) { - if(vstd::contains(CGI->mh->loadedDefs, def->name)) + if(vstd::contains(graphics->mapObjectDefs, def->name)) { - def->handler = CGI->mh->loadedDefs[def->name]; + def->handler = graphics->mapObjectDefs[def->name]; } else { - CGI->mh->loadedDefs[def->name] = def->handler = CDefHandler::giveDefEss(def->name); + graphics->mapObjectDefs[def->name] = def->handler = CDefHandler::giveDefEss(def->name); } } else @@ -361,8 +355,13 @@ void CMapHandler::init() CGI->dobjinfo->gobjs[8][2]->handler = graphics->boatAnims[2]; // Size of visible terrain. - mapW = conf.go()->ac.advmapW; - mapH = conf.go()->ac.advmapH; + int mapW = conf.go()->ac.advmapW; + int mapH = conf.go()->ac.advmapH; + + //sizes of terrain + sizes.x = map->width; + sizes.y = map->height; + sizes.z = map->twoLevel+1; // Total number of visible tiles. Substract the center tile, then // compute the number of tiles on each side, and reassemble. @@ -384,28 +383,6 @@ void CMapHandler::init() offsetX = (mapW - (2*frameW+1)*32)/2; offsetY = (mapH - (2*frameH+1)*32)/2; - std::ifstream ifs(DATA_DIR "/config/townsDefs.txt"); - int ccc; - ifs>>ccc; - for(int i=0;istate->villages[i]; - map->defy.push_back(CGI->state->forts[i]); - } - else - n = CGI->state->capitols[i%ccc]; - - ifs >> n->name; - if(!n) - tlog1 << "*HUGE* Warning - missing town def for " << i << std::endl; - else - map->defy.push_back(n); - } - tlog0<<"\tLoading town def info: "<heroes.size();i++) { if(!map->heroes[i]->defInfo->handler) @@ -417,14 +394,15 @@ void CMapHandler::init() std::for_each(map->defy.begin(),map->defy.end(),processDef); //load h3m defs tlog0<<"\tUnpacking and handling defs: "<players[i].heroesNames.size(); ++j) - { - usedHeroes.insert(map->players[i].heroesNames[j].heroID); - } - } - tlog0<<"\tChecking used heroes: "<players[i].heroesNames.size(); ++j) +// { +// usedHeroes.insert(map->players[i].heroesNames[j].heroID); +// } +// } +// tlog0<<"\tChecking used heroes: "< map->width + frameW) - dx = map->width + frameW - top_tile.x; - if (top_tile.y + dy > map->height + frameH) - dy = map->height + frameH - top_tile.y; + if (top_tile.x + dx > sizes.x + frameW) + dx = sizes.x + frameW - top_tile.x; + if (top_tile.y + dy > sizes.y + frameH) + dy = sizes.y + frameH - top_tile.y; if(!otherHeroAnim) heroAnim = anim; //the same, as it should be @@ -510,7 +488,7 @@ void CMapHandler::terrainRect(int3 top_tile, unsigned char anim, const std::vect for (int bx = 0; bx < dx; bx++, srx+=32) { // Skip column if not in map - if (top_tile.x+bx < 0 || top_tile.x+bx >= map->width) + if (top_tile.x+bx < 0 || top_tile.x+bx >= sizes.x) continue; sry = sry_init; @@ -520,11 +498,11 @@ void CMapHandler::terrainRect(int3 top_tile, unsigned char anim, const std::vect int3 pos(top_tile.x+bx, top_tile.y+by, top_tile.z); //blitted tile position // Skip tile if not in map - if (pos.y < 0 || pos.y >= map->height) + if (pos.y < 0 || pos.y >= sizes.y) continue; const TerrainTile2 & tile = ttiles[pos.x][pos.y][pos.z]; - const TerrainTile &tinfo = *tile.tileInfo; + const TerrainTile &tinfo = map->terrain[pos.x][pos.y][pos.z]; SDL_Rect sr; sr.x=srx; @@ -691,8 +669,8 @@ void CMapHandler::terrainRect(int3 top_tile, unsigned char anim, const std::vect sr.y=sry; sr.h=sr.w=32; - if (pos.x < 0 || pos.x >= map->width || - pos.y < 0 || pos.y >= map->height) + if (pos.x < 0 || pos.x >= sizes.x || + pos.y < 0 || pos.y >= sizes.y) { @@ -706,11 +684,11 @@ void CMapHandler::terrainRect(int3 top_tile, unsigned char anim, const std::vect { if (pos.x >= 0 && pos.y >= 0 && - pos.x < CGI->mh->map->width && - pos.y < CGI->mh->map->height && + pos.x < sizes.x && + pos.y < sizes.y && !(*visibilityMap)[pos.x][pos.y][top_tile.z]) { - SDL_Surface * hide = getVisBitmap(pos.x, pos.y, *visibilityMap, top_tile.z); + SDL_Surface * hide = getVisBitmap(pos, *visibilityMap); CSDL_Ext::blit8bppAlphaTo24bpp(hide, &rtile, extSurf, &sr); } } @@ -719,7 +697,7 @@ void CMapHandler::terrainRect(int3 top_tile, unsigned char anim, const std::vect // TODO: these should be activable by the console #ifdef MARK_BLOCKED_POSITIONS - if(ttiles[pos.x][pos.y][top_tile.z].tileInfo->blocked) //temporary hiding blocked positions + if(map->terrain[pos.x][pos.y][top_tile.z].blocked) //temporary hiding blocked positions { SDL_Rect sr; @@ -732,7 +710,7 @@ void CMapHandler::terrainRect(int3 top_tile, unsigned char anim, const std::vect } #endif #ifdef MARK_VISITABLE_POSITIONS - if(ttiles[pos.x][pos.y][top_tile.z].tileInfo->visitable) //temporary hiding visitable positions + if(map->terrain[pos.x][pos.y][top_tile.z].visitable) //temporary hiding visitable positions { SDL_Rect sr; @@ -851,232 +829,45 @@ void CMapHandler::terrainRect(int3 top_tile, unsigned char anim, const std::vect SDL_SetClipRect(extSurf, &prevClip); //restoring clip_rect } -SDL_Surface * CMapHandler::getVisBitmap(int x, int y, const std::vector< std::vector< std::vector > > & visibilityMap, int lvl) +SDL_Surface * CMapHandler::getVisBitmap( const int3 & pos, const std::vector< std::vector< std::vector > > & visibilityMap ) { - int size = visibilityMap.size()-1; //is tile visible. arrangement: (like num keyboard) - bool d7 = (x>0 && y>0) ? visibilityMap[x-1][y-1][lvl] : 0, //789 - d8 = (y>0) ? visibilityMap[x][y-1][lvl] : 0, //456 - d9 = (y>0 && x0) ? visibilityMap[x-1][y][lvl] : 0, - d5 = visibilityMap[x][y][lvl], //TODO use me - OMFG - d6 = (x0 && y0 && pos.y>0) ? visibilityMap[pos.x-1][pos.y-1][pos.z] : 0, //789 + d8 = (pos.y>0) ? visibilityMap[pos.x][pos.y-1][pos.z] : 0, //456 + d9 = (pos.y>0 && pos.x0) ? visibilityMap[pos.x-1][pos.y][pos.z] : 0, + //d5 = visibilityMap[pos.x][y][pos.z], //TODO use me - OMFG + d6 = (pos.x0 && pos.y=0 -> partial hide, <0 - full hide + if (retBitmapID < 0) { - if (!d3 && !d9 && !d1 && !d7) - return fullHide->ourImages[hideBitmap[x][y][lvl]].bitmap; //fully hidden - if(d2) - return partialHide->ourImages[4].bitmap; //visble bottom - else if (d8) - return partialHide->ourImages[0].bitmap; //visible top - else if (d3) - return partialHide->ourImages[22].bitmap; //visible right bottom corner - else if (d9) - return partialHide->ourImages[15].bitmap; //visible right top corner - else if (d1) - return partialHide->ourImages[34].bitmap; //visible left bottom corner - else if (d7) - return partialHide->ourImages[35].bitmap; //visible left top corner - if (!d2 && !d8) - { - if (d1) - { - if (d3) - { - if (d7) - { - if (d9) - return partialHide->ourImages[21].bitmap; - else - return partialHide->ourImages[43].bitmap; - } - else - { - if (d9) - return partialHide->ourImages[19].bitmap; - else - return partialHide->ourImages[40].bitmap; - } - } - else - { - if (d7) - { - if (d9) - return partialHide->ourImages[42].bitmap; - else - return partialHide->ourImages[39].bitmap; - } - else - return partialHide->ourImages[17].bitmap; - } - } - else - { - if(!d3) - return partialHide->ourImages[18].bitmap; - else if(!d7) - return partialHide->ourImages[16].bitmap; //visible right corner - else if(!d9) - return partialHide->ourImages[41].bitmap; - else - return partialHide->ourImages[20].bitmap; - } - } - if (d2) - { - if(d8) - return partialHide->ourImages[29].bitmap; - else if(d3) - return partialHide->ourImages[1].bitmap; - else - return partialHide->ourImages[5].bitmap; - } - else if (d7) - return partialHide->ourImages[4].bitmap; - else - return partialHide->ourImages[9].bitmap; + retBitmapID = - hideBitmap[pos.x][pos.y][pos.z] - 1; //fully hidden } - else //(d4 && d6 != 0) + + + if (retBitmapID >= 0) { - if (d2) - { - if (d4) - { - if (d6) - { - if (d8) - return partialHide->ourImages[10].bitmap; - else - return partialHide->ourImages[6].bitmap; - } - else - { - if (d8) - return partialHide->ourImages[7].bitmap; - else if (d9) - return partialHide->ourImages[51].bitmap; - else - return partialHide->ourImages[38].bitmap; - } - } - else - { - if (d6) - { - if (d8) - return partialHide->ourImages[44].bitmap; - else if (d7) - return partialHide->ourImages[28].bitmap; - else - return partialHide->ourImages[12].bitmap; - } - else - { - if (d7) - { - if (d9) - return partialHide->ourImages[31].bitmap; - else - return partialHide->ourImages[48].bitmap; - } - else - return partialHide->ourImages[30].bitmap; - } - } - } - else - { - if (d4) - { - if (d6) - { - if (d8) - return partialHide->ourImages[8].bitmap; - else - return partialHide->ourImages[9].bitmap; - } - else - { - if (d8) - { - if (d3) - return partialHide->ourImages[50].bitmap; - else - return partialHide->ourImages[37].bitmap; - } - else - { - if (d3) - { - if (d9) - return partialHide->ourImages[32].bitmap; - else - return partialHide->ourImages[47].bitmap; - } - else - { - if (d9) - return partialHide->ourImages[46].bitmap; - else - return partialHide->ourImages[36].bitmap; - } - } - } - } - else - { - if (d6) - { - if (d8) - { - if (d1) - return partialHide->ourImages[27].bitmap; - else - return partialHide->ourImages[13].bitmap; - } - else - { - if (d7) - { - if (d1) - return partialHide->ourImages[49].bitmap; - else - return partialHide->ourImages[26].bitmap; - } - else - { - if (d1) - return partialHide->ourImages[25].bitmap; - else - { - if (d9) - return partialHide->ourImages[2].bitmap; - else - return partialHide->ourImages[3].bitmap; - } - } - } - } - else - { - if (d1) - { - if (d3) - return partialHide->ourImages[33].bitmap; - else - return partialHide->ourImages[45].bitmap; - } - else - return partialHide->ourImages[24].bitmap; - } - } - } + return graphics->FoWpartialHide->ourImages[retBitmapID].bitmap; + } + else + { + return graphics->FoWfullHide->ourImages[-retBitmapID - 1].bitmap; } - return fullHide->ourImages[0].bitmap; //this case should never happen, but it is better to hide too much than reveal it.... } bool CMapHandler::printObject(const CGObjectInstance *obj) @@ -1321,8 +1112,8 @@ void CMapHandler::updateWater() //shift colors in palettes of water tiles CMapHandler::~CMapHandler() { - delete fullHide; - delete partialHide; + delete graphics->FoWfullHide; + delete graphics->FoWpartialHide; for(int i=0; i < roadDefs.size(); i++) delete roadDefs[i]; @@ -1341,17 +1132,17 @@ CMapHandler::~CMapHandler() CMapHandler::CMapHandler() { - mapW = mapH = 0; frameW = frameH = 0; - fullHide = NULL; - partialHide = NULL; + graphics->FoWfullHide = NULL; + graphics->FoWpartialHide = 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_iterator i = t.objects.begin(); i != t.objects.end(); i++) + TerrainTile2 & tt = ttiles[pos.x][pos.y][pos.z]; + const TerrainTile &t = map->terrain[pos.x][pos.y][pos.z]; + for(std::vector < std::pair >::const_iterator i = tt.objects.begin(); i != tt.objects.end(); i++) { if(i->first->ID == 124) //Hole { @@ -1360,12 +1151,12 @@ void CMapHandler::getTerrainDescr( const int3 &pos, std::string & out, bool terN } } - if(t.tileInfo->siodmyTajemniczyBajt & 128) + if(t.siodmyTajemniczyBajt & 128) out = CGI->generaltexth->names[225]; //Favourable Winds else if(terName) - out = CGI->generaltexth->terrainNames[t.tileInfo->tertype]; + out = CGI->generaltexth->terrainNames[t.tertype]; } TerrainTile2::TerrainTile2() - :tileInfo(0),terbitmap(0) + :terbitmap(0) {} diff --git a/client/mapHandler.h b/client/mapHandler.h index 95004aeb6..bf4af214c 100644 --- a/client/mapHandler.h +++ b/client/mapHandler.h @@ -27,17 +27,12 @@ class CDefEssential; struct TerrainTile2 { - int3 pos; - const TerrainTile *tileInfo; SDL_Surface * terbitmap; //bitmap of terrain std::vector < std::pair > objects; //pointers to objects being on this tile with rects to be easier to blit this tile on screen TerrainTile2(); }; -//pathfinder -// map iDTerenu=>koszt_pola -// map IDdrogi=>koszt_drogi template class PseudoV { public: @@ -73,16 +68,13 @@ public: return inver.size(); } }; + class CMapHandler { public: PseudoV< PseudoV< PseudoV > > ttiles; //informations about map tiles int3 sizes; //map size (x = width, y = height, z = number of levels) - Mapa * map; - - // Size of the map window in pixels. This doesn't have to be a multiple of tiles. - int mapW; - int mapH; + const Mapa * map; // Max number of tiles that will fit in the map screen. Tiles // can be partial on each edges. @@ -99,22 +91,18 @@ public: int offsetX; int offsetY; - std::set usedHeroes; - CDefHandler * fullHide; //for Fog of War - CDefHandler * partialHide; //for For of War + //std::set usedHeroes; std::vector > terrainGraphics; // [terrain id] [view type] [rotation type] std::vector roadDefs; std::vector staticRiverDefs; - std::map loadedDefs; //pointers to loaded defs (key is filename, uppercase) - std::vector > > hideBitmap; //specifies number of graphic that should be used to fully hide a tile CMapHandler(); //c-tor ~CMapHandler(); //d-tor - SDL_Surface * getVisBitmap(int x, int y, const std::vector< std::vector< std::vector > > & visibilityMap, int lvl); + SDL_Surface * getVisBitmap(const int3 & pos, const std::vector< std::vector< std::vector > > & visibilityMap); 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 diff --git a/hch/CObjectHandler.h b/hch/CObjectHandler.h index f28cfa487..f2e1830f0 100644 --- a/hch/CObjectHandler.h +++ b/hch/CObjectHandler.h @@ -394,6 +394,36 @@ public: void onHeroVisit(const CGHeroInstance * h) const; }; +class DLL_EXPORT CSpecObjInfo +{ +public: + virtual ~CSpecObjInfo(){}; +}; + +class DLL_EXPORT CCreGenObjInfo : public CSpecObjInfo +{ +public: + unsigned char player; //owner + bool asCastle; + ui32 identifier; + unsigned char castles[2]; //allowed castles +}; +class DLL_EXPORT CCreGen2ObjInfo : public CSpecObjInfo +{ +public: + unsigned char player; //owner + bool asCastle; + ui32 identifier; + unsigned char castles[2]; //allowed castles + unsigned char minLevel, maxLevel; //minimal and maximal level of creature in dwelling: <0, 6> +}; +class DLL_EXPORT CCreGen3ObjInfo : public CSpecObjInfo +{ +public: + unsigned char player; //owner + unsigned char minLevel, maxLevel; //minimal and maximal level of creature in dwelling: <0, 6> +}; + class DLL_EXPORT CGDwelling : public CArmedInstance { public: diff --git a/lib/map.cpp b/lib/map.cpp index 2b3b189e0..c250bfaea 100644 --- a/lib/map.cpp +++ b/lib/map.cpp @@ -81,64 +81,6 @@ static unsigned char reverse(unsigned char arg) } return ret; } -static EDefType getDefType(CGDefInfo * a) -{ - switch(a->id) - { - case 5: case 65: case 66: case 67: case 68: case 69: - return ARTIFACT_DEF; //handled - case 6: - return PANDORA_DEF; //hanled - case 10: - return EVENTOBJ_DEF; //??? - case 26: - return EVENTOBJ_DEF; //handled - case 33: - return GARRISON_DEF; //handled - case 34: case 70: case 62: //70 - random hero //62 - prison - return HERO_DEF; //handled - case 36: - return GRAIL_DEF; //hanled - case 53: case 17: case 18: case 19: case 20: case 42: case 87: case 220://cases 17 - 20 and 42 - tests - return PLAYERONLY_DEF; //handled - case 54: case 71: case 72: case 73: case 74: case 75: case 162: case 163: case 164: - return CREATURES_DEF; //handled - case 59: - return SIGN_DEF; //handled - case 77: - return TOWN_DEF; //can be problematic, but handled - case 79: case 76: - return RESOURCE_DEF; //handled - case 81: - return SCHOLAR_DEF; //handled - case 83: - return SEERHUT_DEF; //handled - case 91: - return SIGN_DEF; //handled - case 88: case 89: case 90: - return SHRINE_DEF; //handled - case 93: - return SPELLSCROLL_DEF; //handled - case 98: - return TOWN_DEF; //handled - case 113: - return WITCHHUT_DEF; //handled - case 214: - return HEROPLACEHOLDER_DEF; //partially handled - case 215: case 9: //??? - return BORDERGUARD_DEF; //handled by analogy to seer huts ;] - case 216: - return CREGEN2_DEF; //handled - case 217: - return CREGEN_DEF; //handled - case 218: - return CREGEN3_DEF; //handled - case 219: - return GARRISON_DEF; //handled - default: - return TERRAINOBJ_DEF; // nothing to be handled - } -} static CCreatureSet readCreatureSet(const unsigned char * bufor, int &i, int number, bool version) //version==true for >RoE maps { @@ -2106,12 +2048,12 @@ void Mapa::loadQuest(CQuest * guard, const unsigned char * bufor, int & i) guard->isCustom = false; //randomize all if any text is missing } -TerrainTile & Mapa::getTile( int3 tile ) +TerrainTile & Mapa::getTile( const int3 & tile ) { return terrain[tile.x][tile.y][tile.z]; } -const TerrainTile & Mapa::getTile( int3 tile ) const +const TerrainTile & Mapa::getTile( const int3 & tile ) const { return terrain[tile.x][tile.y][tile.z]; } diff --git a/lib/map.h b/lib/map.h index 5348c3d08..c7cb13506 100644 --- a/lib/map.h +++ b/lib/map.h @@ -31,40 +31,8 @@ class CGCreature; class CQuest; class CGTownInstance; -enum EDefType {TOWN_DEF, HERO_DEF, CREATURES_DEF, SEERHUT_DEF, RESOURCE_DEF, TERRAINOBJ_DEF, - EVENTOBJ_DEF, SIGN_DEF, GARRISON_DEF, ARTIFACT_DEF, WITCHHUT_DEF, SCHOLAR_DEF, PLAYERONLY_DEF, - SHRINE_DEF, SPELLSCROLL_DEF, PANDORA_DEF, GRAIL_DEF, CREGEN_DEF, CREGEN2_DEF, CREGEN3_DEF, - BORDERGUARD_DEF, HEROPLACEHOLDER_DEF}; -class DLL_EXPORT CSpecObjInfo -{ -public: - virtual ~CSpecObjInfo(){}; -}; -class DLL_EXPORT CCreGenObjInfo : public CSpecObjInfo -{ -public: - unsigned char player; //owner - bool asCastle; - ui32 identifier; - unsigned char castles[2]; //allowed castles -}; -class DLL_EXPORT CCreGen2ObjInfo : public CSpecObjInfo -{ -public: - unsigned char player; //owner - bool asCastle; - ui32 identifier; - unsigned char castles[2]; //allowed castles - unsigned char minLevel, maxLevel; //minimal and maximal level of creature in dwelling: <0, 6> -}; -class DLL_EXPORT CCreGen3ObjInfo : public CSpecObjInfo -{ -public: - unsigned char player; //owner - unsigned char minLevel, maxLevel; //minimal and maximal level of creature in dwelling: <0, 6> -}; struct DLL_EXPORT TerrainTile { enum EterrainType {border=-1, dirt, sand, grass, snow, swamp, rough, subterranean, lava, water, rock}; @@ -294,11 +262,13 @@ struct DLL_EXPORT Mapa : public CMapHeader Mapa(std::string filename); //creates map structure from .h3m file Mapa(); ~Mapa(); - TerrainTile &getTile(int3 tile); - const TerrainTile &getTile(int3 tile) const; + TerrainTile &getTile(const int3 & tile); + const TerrainTile &getTile(const int3 & tile) const; CGHeroInstance * getHero(int ID, int mode=0); bool isInTheMap(const int3 &pos) const; bool isWaterTile(const int3 &pos) const; //out-of-pos safe + + void loadingHelper(); template void serialize(Handler &h, const int formatVersion) { h & static_cast(*this);