diff --git a/hch/CObjectHandler.cpp b/hch/CObjectHandler.cpp index 330ed7f95..8f6669801 100644 --- a/hch/CObjectHandler.cpp +++ b/hch/CObjectHandler.cpp @@ -396,7 +396,10 @@ int CGObjectInstance::getSightRadious() const { return 3; } - +void CGObjectInstance::getSightTiles(std::set &tiles) const //returns reference to the set +{ + cb->getTilesInRange(tiles, pos, getSightRadious(), tempOwner, 1); +} int3 CGObjectInstance::getVisitableOffset() const { for(int y = 0; y < 6; y++) @@ -1422,7 +1425,7 @@ int CGTownInstance::getSightRadious() const //returns sight distance if (subID == 2) //tower { if ((builtBuildings.find(17)) != builtBuildings.end()) //skyship - return cb->getMapSize().x + cb->getMapSize().y; + return -1; //entire map else if ((builtBuildings.find(21)) != builtBuildings.end()) //lookout tower return 20; } diff --git a/hch/CObjectHandler.h b/hch/CObjectHandler.h index 36038c6fd..3ebb14e34 100644 --- a/hch/CObjectHandler.h +++ b/hch/CObjectHandler.h @@ -144,6 +144,7 @@ public: virtual int3 getSightCenter() const; //"center" tile from which the sight distance is calculated virtual int getSightRadious() const; //sight distance (should be used if player-owned structure) + void getSightTiles(std::set &tiles) const; //returns reference to the set int getOwner() const; void setOwner(int ow); int getWidth() const; //returns width of object graphic in tiles diff --git a/lib/CGameState.cpp b/lib/CGameState.cpp index 54cb2862a..69e9cc555 100644 --- a/lib/CGameState.cpp +++ b/lib/CGameState.cpp @@ -1394,9 +1394,11 @@ void CGameState::init(StartInfo * si, Mapa * map, int Seed) BOOST_FOREACH(CGObjectInstance *obj, map->objects) { if(obj->tempOwner != k->first) continue; //not a flagged object - + /* int3 objCenter = obj->getSightCenter(); int radious = obj->getSightRadious(); + if (radious == -1) //maybe better handle it via getTilesInRange as below? + radious = map->width + map->height; for (int xd = std::max(objCenter.x - radious , 0); xd <= std::min(objCenter.x + radious, map->width - 1); xd++) { @@ -1407,6 +1409,13 @@ void CGameState::init(StartInfo * si, Mapa * map, int Seed) k->second.fogOfWarMap[xd][yd][objCenter.z] = 1; } } + */ + std::set tiles; + obj->getSightTiles(tiles); + BOOST_FOREACH(int3 tile, tiles) + { + k->second.fogOfWarMap[tile.x][tile.y][tile.z] = 1; + } } //for(int xd=0; xdwidth; ++xd) //revealing part of map around heroes diff --git a/lib/IGameCallback.cpp b/lib/IGameCallback.cpp index 68a45c902..459944057 100644 --- a/lib/IGameCallback.cpp +++ b/lib/IGameCallback.cpp @@ -100,19 +100,24 @@ void IGameCallback::getTilesInRange( std::set &tiles, int3 pos, int radiou tlog1 << "Illegal call to getTilesInRange!\n"; return; } - - for (int xd = std::max(pos.x - radious , 0); xd <= std::min(pos.x + radious, gs->map->width - 1); xd++) + if (radious == -1) //reveal entire map + getAllTiles (tiles, player, -1, 0); + else { - for (int yd = std::max(pos.y - radious, 0); yd <= std::min(pos.y + radious, gs->map->height - 1); yd++) + PlayerState * plr = &gs->players.find(player)->second; + for (int xd = std::max(pos.x - radious , 0); xd <= std::min(pos.x + radious, gs->map->width - 1); xd++) { - double distance = pos.dist2d(int3(xd,yd,pos.z)) - 0.5; - if(distance <= radious) + for (int yd = std::max(pos.y - radious, 0); yd <= std::min(pos.y + radious, gs->map->height - 1); yd++) { - if(player < 0 - || (mode == 1 && gs->players.find(player)->second.fogOfWarMap[xd][yd][pos.z]==0) - || (mode == -1 && gs->players.find(player)->second.fogOfWarMap[xd][yd][pos.z]==1) - ) - tiles.insert(int3(xd,yd,pos.z)); + double distance = pos.dist2d(int3(xd,yd,pos.z)) - 0.5; + if(distance <= radious) + { + if(player < 0 + || (mode == 1 && plr->fogOfWarMap[xd][yd][pos.z]==0) + || (mode == -1 && plr->fogOfWarMap[xd][yd][pos.z]==1) + ) + tiles.insert(int3(xd,yd,pos.z)); + } } } } @@ -122,7 +127,7 @@ void IGameCallback::getAllTiles (std::set &tiles, int player/*=-1*/, int l { if(player >= PLAYER_LIMIT) { - tlog1 << "Illegal call to getTilesInRange!\n"; + tlog1 << "Illegal call to getAllTiles !\n"; return; } bool water = surface == 0 || surface == 2, diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index f577bb0f0..eb027cadd 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -2039,9 +2039,16 @@ bool CGameHandler::buildStructure( si32 tid, si32 bid ) sendAndApply(&ssi); } + //reveal ground for lookout tower + /* sdl conflict ns.bid.insert(bid); ns.builded = t->builded + 1; sendAndApply(&ns); + */ + + FoWChange fw; + t->getSightTiles(fw.tiles); + sendAndApply(&fw); SetResources sr; sr.player = t->tempOwner; @@ -2061,12 +2068,6 @@ bool CGameHandler::buildStructure( si32 tid, si32 bid ) vistiCastleObjects (t, t->visitingHero); if(t->garrisonHero) vistiCastleObjects (t, t->garrisonHero); - //reveal ground for lookout tower - FoWChange fw; - fw.player = t->tempOwner; - fw.mode = 1; - getTilesInRange(fw.tiles, t->pos, t->getSightRadious(), t->tempOwner,1); - sendAndApply(&fw); return true; }