From 10f888a483e22e5a0707fbd9d53bfdbfefadf811 Mon Sep 17 00:00:00 2001 From: Vadim Markovtsev Date: Wed, 20 Jan 2016 10:44:13 +0300 Subject: [PATCH 1/4] Fix obelisks puzzle revealing Teams and players were messed up in lib; hardcoded constants were refactored. --- AI/VCAI/Goals.cpp | 2 +- client/CPlayerInterface.cpp | 22 +++++----- lib/CGameInfoCallback.cpp | 76 +++++++++++++++++----------------- lib/CGameInfoCallback.h | 5 +-- lib/mapObjects/CQuest.cpp | 6 +-- lib/mapObjects/CQuest.h | 2 + lib/mapObjects/MiscObjects.cpp | 62 +++++++++++++++------------ lib/mapObjects/MiscObjects.h | 3 ++ 8 files changed, 95 insertions(+), 83 deletions(-) diff --git a/AI/VCAI/Goals.cpp b/AI/VCAI/Goals.cpp index 4931e4e19..540e56e6c 100644 --- a/AI/VCAI/Goals.cpp +++ b/AI/VCAI/Goals.cpp @@ -275,7 +275,7 @@ TSubgoal Win::whatToDoToAchieve() // 0.85 -> radius now 2 tiles // 0.95 -> 1 tile radius, position is fully known // AFAIK H3 AI does something like this - int3 grailPos = cb->getGrailPos(ratio); + int3 grailPos = cb->getGrailPos(&ratio); if(ratio > 0.99) { return sptr (Goals::DigAtTile(grailPos)); diff --git a/client/CPlayerInterface.cpp b/client/CPlayerInterface.cpp index 33040aef8..97ebe9fa6 100644 --- a/client/CPlayerInterface.cpp +++ b/client/CPlayerInterface.cpp @@ -119,7 +119,7 @@ CPlayerInterface::CPlayerInterface(PlayerColor Player) isAutoFightOn = false; duringMovement = false; - ignoreEvents = false; + ignoreEvents = false; } CPlayerInterface::~CPlayerInterface() @@ -824,16 +824,16 @@ BattleAction CPlayerInterface::activeStack(const CStack * stack) //called when i //tidy up BattleAction ret = *(b->givenCommand->data); vstd::clear_pointer(b->givenCommand->data); - + if(ret.actionType == Battle::CANCEL) { if(stackId != ret.stackNumber) logGlobal->error("Not current active stack action canceled"); - logGlobal->traceStream() << "Canceled command for " << stackName; + logGlobal->traceStream() << "Canceled command for " << stackName; } else logGlobal->traceStream() << "Giving command for " << stackName; - + return ret; } @@ -1610,11 +1610,11 @@ void CPlayerInterface::update() { // Make sure that gamestate won't change when GUI objects may obtain its parts on event processing or drawing request boost::shared_lock gsLock(cb->getGsMutex()); - - // While mutexes were locked away we may be have stopped being the active interface + + // While mutexes were locked away we may be have stopped being the active interface if(LOCPLINT != this) return; - + //if there are any waiting dialogs, show them if((howManyPeople <= 1 || makingTurn) && !dialogs.empty() && !showingDialog->get()) { @@ -2170,7 +2170,7 @@ void CPlayerInterface::showPuzzleMap() //TODO: interface should not know the real position of Grail... double ratio = 0; - int3 grailPos = cb->getGrailPos(ratio); + int3 grailPos = cb->getGrailPos(&ratio); GH.pushInt(new CPuzzleWindow(grailPos, ratio)); } @@ -2195,7 +2195,7 @@ void CPlayerInterface::advmapSpellCast(const CGHeroInstance * caster, int spellI int level = caster->getSpellSchoolLevel(spell); adventureInt->worldViewOptions.showAllTerrain = (level>2); } - + auto castSoundPath = spell->getCastSound(); if (!castSoundPath.empty()) CCS->soundh->playSound(castSoundPath); @@ -2783,8 +2783,8 @@ void CPlayerInterface::showWorldViewEx(const std::vector& objectP { EVENT_HANDLER_CALLED_BY_CLIENT; //TODO: showWorldViewEx - + std::copy(objectPositions.begin(), objectPositions.end(), std::back_inserter(adventureInt->worldViewOptions.iconPositions)); - + viewWorldMap(); } diff --git a/lib/CGameInfoCallback.cpp b/lib/CGameInfoCallback.cpp index 9abf44444..f0c68c3d8 100644 --- a/lib/CGameInfoCallback.cpp +++ b/lib/CGameInfoCallback.cpp @@ -229,13 +229,13 @@ bool CGameInfoCallback::getTownInfo(const CGObjectInstance * town, InfoAboutTown { if(!detailed && nullptr != selectedObject) { - const CGHeroInstance * selectedHero = dynamic_cast(selectedObject); + const CGHeroInstance * selectedHero = dynamic_cast(selectedObject); if(nullptr != selectedHero) - detailed = selectedHero->hasVisions(town, 1); + detailed = selectedHero->hasVisions(town, 1); } - + dest.initFromTown(static_cast(town), detailed); - } + } else if(town->ID == Obj::GARRISON || town->ID == Obj::GARRISON2) dest.initFromArmy(static_cast(town), detailed); else @@ -268,28 +268,28 @@ bool CGameInfoCallback::getHeroInfo(const CGObjectInstance * hero, InfoAboutHero ERROR_RET_VAL_IF(!isVisible(h->getPosition(false)), "That hero is not visible!", false); bool accessFlag = hasAccess(h->tempOwner); - + if(!accessFlag && nullptr != selectedObject) { - const CGHeroInstance * selectedHero = dynamic_cast(selectedObject); + const CGHeroInstance * selectedHero = dynamic_cast(selectedObject); if(nullptr != selectedHero) - accessFlag = selectedHero->hasVisions(hero, 1); + accessFlag = selectedHero->hasVisions(hero, 1); } - + dest.initFromHero(h, accessFlag); - + //DISGUISED bonus implementation - + if(getPlayerRelations(getLocalPlayer(), hero->tempOwner) == PlayerRelations::ENEMIES) { - //todo: bonus cashing + //todo: bonus cashing int disguiseLevel = h->valOfBonuses(Selector::typeSubtype(Bonus::DISGUISED, 0)); - - auto doBasicDisguise = [disguiseLevel](InfoAboutHero & info) + + auto doBasicDisguise = [disguiseLevel](InfoAboutHero & info) { int maxAIValue = 0; const CCreature * mostStrong = nullptr; - + for(auto & elem : info.army) { if(elem.second.type->AIValue > maxAIValue) @@ -298,7 +298,7 @@ bool CGameInfoCallback::getHeroInfo(const CGObjectInstance * hero, InfoAboutHero mostStrong = elem.second.type; } } - + if(nullptr == mostStrong)//just in case logGlobal->errorStream() << "CGameInfoCallback::getHeroInfo: Unable to select most strong stack" << disguiseLevel; else @@ -307,25 +307,25 @@ bool CGameInfoCallback::getHeroInfo(const CGObjectInstance * hero, InfoAboutHero elem.second.type = mostStrong; } }; - - auto doAdvancedDisguise = [accessFlag, &doBasicDisguise](InfoAboutHero & info) + + auto doAdvancedDisguise = [accessFlag, &doBasicDisguise](InfoAboutHero & info) { doBasicDisguise(info); - + for(auto & elem : info.army) elem.second.count = 0; }; - - auto doExpertDisguise = [this,h](InfoAboutHero & info) + + auto doExpertDisguise = [this,h](InfoAboutHero & info) { for(auto & elem : info.army) elem.second.count = 0; - + const auto factionIndex = getStartInfo(false)->playerInfos.at(h->tempOwner).castle; - + int maxAIValue = 0; const CCreature * mostStrong = nullptr; - + for(auto creature : VLC->creh->creatures) { if(creature->faction == factionIndex && creature->AIValue > maxAIValue) @@ -334,35 +334,35 @@ bool CGameInfoCallback::getHeroInfo(const CGObjectInstance * hero, InfoAboutHero mostStrong = creature; } } - + if(nullptr != mostStrong) //possible, faction may have no creatures at all for(auto & elem : info.army) elem.second.type = mostStrong; - }; - - + }; + + switch (disguiseLevel) { case 0: //no bonus at all - do nothing - break; + break; case 1: doBasicDisguise(dest); - break; + break; case 2: doAdvancedDisguise(dest); - break; + break; case 3: doExpertDisguise(dest); - break; + break; default: //invalid value logGlobal->errorStream() << "CGameInfoCallback::getHeroInfo: Invalid DISGUISED bonus value " << disguiseLevel; break; } - + } - + return true; } @@ -486,7 +486,7 @@ std::shared_ptr> CGameInfoCallback::getAllVi boost::multi_array tileArray(boost::extents[width][height][levels]); - + for (size_t x = 0; x < width; x++) for (size_t y = 0; y < height; y++) for (size_t z = 0; z < levels; z++) @@ -723,15 +723,16 @@ int CPlayerSpecificInfoCallback::getHeroSerial(const CGHeroInstance * hero, bool return -1; } -int3 CPlayerSpecificInfoCallback::getGrailPos( double &outKnownRatio ) +int3 CPlayerSpecificInfoCallback::getGrailPos( double *outKnownRatio ) { if (!player || CGObelisk::obeliskCount == 0) { - outKnownRatio = 0.0; + *outKnownRatio = 0.0; } else { - outKnownRatio = static_cast(CGObelisk::visited[gs->getPlayerTeam(*player)->id]) / CGObelisk::obeliskCount; + *outKnownRatio = static_cast(CGObelisk::visited[gs->getPlayerTeam(*player)->id]) + / CGObelisk::obeliskCount; } return gs->map->grailPos; } @@ -964,4 +965,3 @@ void IGameEventRealizer::setObjProperty(ObjectInstanceID objid, int prop, si64 v sob.val = static_cast(val); commitPackage(&sob); } - diff --git a/lib/CGameInfoCallback.h b/lib/CGameInfoCallback.h index 81c691e71..4d2903657 100644 --- a/lib/CGameInfoCallback.h +++ b/lib/CGameInfoCallback.h @@ -125,7 +125,7 @@ class DLL_LINKAGE CPlayerSpecificInfoCallback : public CGameInfoCallback public: int howManyTowns() const; int howManyHeroes(bool includeGarrisoned = true) const; - int3 getGrailPos(double &outKnownRatio); + int3 getGrailPos(double *outKnownRatio); boost::optional getMyColor() const; std::vector getTownsInfo(bool onlyOur = true) const; //true -> only owned; false -> all visible @@ -139,7 +139,7 @@ public: int getResourceAmount(Res::ERes type) const; TResources getResourceAmount() const; - const std::vector< std::vector< std::vector > > & getVisibilityMap()const; //returns visibility map + const std::vector< std::vector< std::vector > > & getVisibilityMap()const; //returns visibility map const PlayerSettings * getPlayerSettings(PlayerColor color) const; }; @@ -154,4 +154,3 @@ public: virtual void showInfoDialog(const std::string &msg, PlayerColor player); }; - diff --git a/lib/mapObjects/CQuest.cpp b/lib/mapObjects/CQuest.cpp index b8964a342..c097ef511 100644 --- a/lib/mapObjects/CQuest.cpp +++ b/lib/mapObjects/CQuest.cpp @@ -533,7 +533,7 @@ void CGSeerHut::newTurn() const { if (quest->lastDay >= 0 && quest->lastDay < cb->getDate()-1) //time is up { - cb->setObjProperty (id, 10, CQuest::COMPLETE); + cb->setObjProperty (id, CGSeerHut::OBJPROP_VISITED, CQuest::COMPLETE); } } @@ -550,7 +550,7 @@ void CGSeerHut::onHeroVisit( const CGHeroInstance * h ) const if (firstVisit) { isCustom = quest->isCustomFirst; - cb->setObjProperty (id, 10, CQuest::IN_PROGRESS); + cb->setObjProperty (id, CGSeerHut::OBJPROP_VISITED, CQuest::IN_PROGRESS); AddQuest aq; aq.quest = QuestInfo (quest, this, visitablePos()); @@ -645,7 +645,7 @@ void CGSeerHut::finishQuest(const CGHeroInstance * h, ui32 accept) const default: break; } - cb->setObjProperty (id, 10, CQuest::COMPLETE); //mission complete + cb->setObjProperty (id, CGSeerHut::OBJPROP_VISITED, CQuest::COMPLETE); //mission complete completeQuest(h); //make sure to remove QuestGuard at the very end } } diff --git a/lib/mapObjects/CQuest.h b/lib/mapObjects/CQuest.h index cc9fd9063..18d35df98 100644 --- a/lib/mapObjects/CQuest.h +++ b/lib/mapObjects/CQuest.h @@ -118,6 +118,8 @@ public: h & rewardType & rID & rVal & seerName; } protected: + static constexpr int OBJPROP_VISITED = 10; + void setPropertyDer(ui8 what, ui32 val) override; }; diff --git a/lib/mapObjects/MiscObjects.cpp b/lib/mapObjects/MiscObjects.cpp index dcdad9a27..587bb02b4 100644 --- a/lib/mapObjects/MiscObjects.cpp +++ b/lib/mapObjects/MiscObjects.cpp @@ -60,7 +60,7 @@ static std::string & visitedTxt(const bool visited) void CPlayersVisited::setPropertyDer( ui8 what, ui32 val ) { - if(what == 10) + if(what == CPlayersVisited::OBJPROP_VISITED) players.insert(PlayerColor(val)); } @@ -103,16 +103,16 @@ std::string CGCreature::getHoverText(const CGHeroInstance * hero) const { std::string hoverName; if(hero->hasVisions(this, 0)) - { + { MetaString ms; ms << stacks.begin()->second->count; ms << " " ; ms.addTxt(MetaString::CRE_PL_NAMES,subID); - + ms << "\n"; - + int decision = takenAction(hero, true); - + switch (decision) { case FIGHT: @@ -123,19 +123,19 @@ std::string CGCreature::getHoverText(const CGHeroInstance * hero) const break; case JOIN_FOR_FREE: ms.addTxt(MetaString::GENERAL_TXT,243); - break; + break; default: //decision = cost in gold VLC->generaltexth->allTexts[244]; - ms << boost::to_string(boost::format(VLC->generaltexth->allTexts[244]) % decision); + ms << boost::to_string(boost::format(VLC->generaltexth->allTexts[244]) % decision); break; - } + } - ms.toString(hoverName); + ms.toString(hoverName); } else { - hoverName = getHoverText(hero->tempOwner); - } + hoverName = getHoverText(hero->tempOwner); + } const JsonNode & texts = VLC->generaltexth->localizedTexts["adventureMap"]["monsterThreat"]; @@ -1310,7 +1310,7 @@ void CGWitchHut::onHeroVisit( const CGHeroInstance * h ) const iw.soundID = soundBase::gazebo; iw.player = h->getOwner(); if(!wasVisited(h->tempOwner)) - cb->setObjProperty(id, 10, h->tempOwner.getNum()); + cb->setObjProperty(id, CGWitchHut::OBJPROP_VISITED, h->tempOwner.getNum()); ui32 txt_id; if(h->getSecSkillLevel(SecondarySkill(ability))) //you already know this skill { @@ -1420,7 +1420,7 @@ void CGShrine::onHeroVisit( const CGHeroInstance * h ) const } if(!wasVisited(h->tempOwner)) - cb->setObjProperty(id, 10, h->tempOwner.getNum()); + cb->setObjProperty(id, CGShrine::OBJPROP_VISITED, h->tempOwner.getNum()); InfoWindow iw; iw.soundID = soundBase::temple; @@ -1745,7 +1745,7 @@ void CGShipyard::getOutOffsets( std::vector &offsets ) const int3(-3,0,0), int3(1,0,0), //AB int3(-3,1,0), int3(1,1,0), int3(-2,1,0), int3(0,1,0), int3(-1,1,0), //CDEFG int3(-3,-1,0), int3(1,-1,0), int3(-2,-1,0), int3(0,-1,0), int3(-1,-1,0) //HIJKL - }; + }; } void CGShipyard::onHeroVisit( const CGHeroInstance * h ) const @@ -1821,7 +1821,7 @@ void CCartographer::blockingDialogAnswered(const CGHeroInstance *hero, ui32 answ //water = 0; land = 1; underground = 2; cb->getAllTiles (fw.tiles, hero->tempOwner, subID - 1, !subID + 1); //reveal appropriate tiles cb->sendAndApply (&fw); - cb->setObjProperty (id, 10, hero->tempOwner.getNum()); + cb->setObjProperty (id, CCartographer::OBJPROP_VISITED, hero->tempOwner.getNum()); } } @@ -1843,11 +1843,13 @@ void CGObelisk::onHeroVisit( const CGHeroInstance * h ) const iw.text.addTxt(MetaString::ADVOB_TXT, 96); cb->sendAndApply(&iw); - cb->setObjProperty(id, 20, h->tempOwner.getNum()); //increment general visited obelisks counter + // increment general visited obelisks counter + cb->setObjProperty(id, CGObelisk::OBJPROP_INC, team.getNum()); openWindow(OpenWindow::PUZZLE_MAP, h->tempOwner.getNum()); - cb->setObjProperty(id, 10, h->tempOwner.getNum()); //mark that particular obelisk as visited + // mark that particular obelisk as visited + cb->setObjProperty(id, CGObelisk::OBJPROP_VISITED, h->tempOwner.getNum()); } else { @@ -1869,20 +1871,26 @@ std::string CGObelisk::getHoverText(PlayerColor player) const void CGObelisk::setPropertyDer( ui8 what, ui32 val ) { - CPlayersVisited::setPropertyDer(what, val); switch(what) { - case 20: - assert(val < PlayerColor::PLAYER_LIMIT_I); - visited[TeamID(val)]++; + case CGObelisk::OBJPROP_INC: + { + assert(val < PlayerColor::PLAYER_LIMIT_I); + auto progress = ++visited[TeamID(val)]; + logGlobal->debugStream() << boost::format("Player %d: obelisk progress %d / %d") + % val % static_cast(progress) % static_cast(obeliskCount); - if(visited[TeamID(val)] > obeliskCount) - { - logGlobal->errorStream() << "Error: Visited " << visited[TeamID(val)] << "\t\t" << obeliskCount; - assert(0); - } + if(progress > obeliskCount) + { + logGlobal->errorStream() << "Error: Visited " << progress << "\t\t" << obeliskCount; + assert(0); + } - break; + break; + } + default: + CPlayersVisited::setPropertyDer(what, val); + break; } } diff --git a/lib/mapObjects/MiscObjects.h b/lib/mapObjects/MiscObjects.h index aa3afe4c6..de358318d 100644 --- a/lib/mapObjects/MiscObjects.h +++ b/lib/mapObjects/MiscObjects.h @@ -28,6 +28,8 @@ public: h & static_cast(*this); h & players; } + + static constexpr int OBJPROP_VISITED = 10; }; class DLL_LINKAGE CGCreature : public CArmedInstance //creatures on map @@ -451,6 +453,7 @@ class DLL_LINKAGE CGDenOfthieves : public CGObjectInstance class DLL_LINKAGE CGObelisk : public CPlayersVisited { public: + static constexpr int OBJPROP_INC = 20; static ui8 obeliskCount; //how many obelisks are on map static std::map visited; //map: team_id => how many obelisks has been visited From bb3a31f3ff339f1d8d5b4e6a7f96ad87ab56e046 Mon Sep 17 00:00:00 2001 From: Vadim Markovtsev Date: Wed, 20 Jan 2016 11:14:03 +0300 Subject: [PATCH 2/4] Mark obelisk visited for all players in the team --- lib/mapObjects/MiscObjects.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/mapObjects/MiscObjects.cpp b/lib/mapObjects/MiscObjects.cpp index 587bb02b4..6fa3640c7 100644 --- a/lib/mapObjects/MiscObjects.cpp +++ b/lib/mapObjects/MiscObjects.cpp @@ -1848,8 +1848,11 @@ void CGObelisk::onHeroVisit( const CGHeroInstance * h ) const openWindow(OpenWindow::PUZZLE_MAP, h->tempOwner.getNum()); - // mark that particular obelisk as visited - cb->setObjProperty(id, CGObelisk::OBJPROP_VISITED, h->tempOwner.getNum()); + // mark that particular obelisk as visited for all players in the team + for (auto & color : ts->players) + { + cb->setObjProperty(id, CGObelisk::OBJPROP_VISITED, color.getNum()); + } } else { From 1a2cd36df80b44a66d542b64fdcc47e1b0082c8f Mon Sep 17 00:00:00 2001 From: Vadim Markovtsev Date: Wed, 20 Jan 2016 12:43:07 +0300 Subject: [PATCH 3/4] Initialize obelisks count to 0 Otherwise every time player starts with a random number. --- lib/mapObjects/MiscObjects.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mapObjects/MiscObjects.cpp b/lib/mapObjects/MiscObjects.cpp index 6fa3640c7..1889dacd8 100644 --- a/lib/mapObjects/MiscObjects.cpp +++ b/lib/mapObjects/MiscObjects.cpp @@ -24,7 +24,7 @@ #include "../CPlayerState.h" std::map > CGMagi::eyelist; -ui8 CGObelisk::obeliskCount; //how many obelisks are on map +ui8 CGObelisk::obeliskCount = 0; //how many obelisks are on map std::map CGObelisk::visited; //map: team_id => how many obelisks has been visited ///helpers From e8db456bebcca238a1e83093064f9a8bd8bcdba0 Mon Sep 17 00:00:00 2001 From: Vadim Markovtsev Date: Wed, 20 Jan 2016 13:02:52 +0300 Subject: [PATCH 4/4] Reset obelisks upon game end Otherwise, the static variables are preserved and lead to wrong values in next new game. --- client/Client.cpp | 64 ++++++++++++++++++---------------- lib/mapObjects/MiscObjects.cpp | 6 ++++ lib/mapObjects/MiscObjects.h | 1 + 3 files changed, 40 insertions(+), 31 deletions(-) diff --git a/client/Client.cpp b/client/Client.cpp index 8f8ef5be0..1faea77fa 100644 --- a/client/Client.cpp +++ b/client/Client.cpp @@ -59,8 +59,8 @@ template class CApplyOnCL; class CBaseForCLApply { public: - virtual void applyOnClAfter(CClient *cl, void *pack) const =0; - virtual void applyOnClBefore(CClient *cl, void *pack) const =0; + virtual void applyOnClAfter(CClient *cl, void *pack) const =0; + virtual void applyOnClBefore(CClient *cl, void *pack) const =0; virtual ~CBaseForCLApply(){} template static CBaseForCLApply *getApplier(const U * t=nullptr) @@ -144,7 +144,7 @@ void CClient::waitForMoveAndSend(PlayerColor color) { logNetwork->traceStream() << "Send battle action to server: " << ba; MakeAction temp_action(ba); - sendRequest(&temp_action, color); + sendRequest(&temp_action, color); } return; } @@ -169,8 +169,8 @@ void CClient::run() while(!terminate) { CPack *pack = serv->retreivePack(); //get the package from the server - - if (terminate) + + if (terminate) { vstd::clear_pointer(pack); break; @@ -178,10 +178,10 @@ void CClient::run() handlePack(pack); } - } + } //catch only asio exceptions catch (const boost::system::system_error& e) - { + { logNetwork->errorStream() << "Lost connection to server, ending listening thread!"; logNetwork->errorStream() << e.what(); if(!terminate) //rethrow (-> boom!) only if closing connection was unexpected @@ -219,18 +219,20 @@ void CClient::endGame( bool closeConnection /*= true*/ ) GH.curInt = nullptr; { boost::unique_lock un(*LOCPLINT->pim); - logNetwork->infoStream() << "Ending current game!"; + logNetwork->infoStream() << "Ending current game!"; if(GH.topInt()) + { GH.topInt()->deactivate(); + } GH.listInt.clear(); GH.objsToBlit.clear(); GH.statusbar = nullptr; - logNetwork->infoStream() << "Removed GUI."; + logNetwork->infoStream() << "Removed GUI."; vstd::clear_pointer(const_cast(CGI)->mh); vstd::clear_pointer(gs); - logNetwork->infoStream() << "Deleted mapHandler and gameState."; + logNetwork->infoStream() << "Deleted mapHandler and gameState."; LOCPLINT = nullptr; } @@ -238,9 +240,9 @@ void CClient::endGame( bool closeConnection /*= true*/ ) battleints.clear(); callbacks.clear(); battleCallbacks.clear(); - logNetwork->infoStream() << "Deleted playerInts."; - - logNetwork->infoStream() << "Client stopped."; + CGObelisk::reset(); + logNetwork->infoStream() << "Deleted playerInts."; + logNetwork->infoStream() << "Client stopped."; } #if 1 @@ -320,7 +322,7 @@ void CClient::loadGame(const std::string & fname, const bool server, const std:: *serv << ui8(3) << ui8(loadNumPlayers); //load game; one client if single-player *serv << fname; *serv >> pom8; - if(pom8) + if(pom8) throw std::runtime_error("Server cannot open the savegame!"); else logNetwork->infoStream() << "Server opened savegame properly."; @@ -376,7 +378,7 @@ void CClient::newGame( CConnection *con, StartInfo *si ) { enum {SINGLE, HOST, GUEST} networkMode = SINGLE; - if (con == nullptr) + if (con == nullptr) { CServerHandler sh; serv = sh.connectToServer(); @@ -459,7 +461,7 @@ void CClient::newGame( CConnection *con, StartInfo *si ) logNetwork->infoStream() << boost::format("Player %s will be lead by %s") % color % AiToGive; installNewPlayerInterface(CDynLibHandler::getNewAI(AiToGive), color); } - else + else { installNewPlayerInterface(std::make_shared(color), color); humanPlayers++; @@ -502,7 +504,7 @@ void CClient::newGame( CConnection *con, StartInfo *si ) // nm->giveActionCB(this); // nm->giveInfoCB(this); // nm->init(); -// +// // erm = nm; //something tells me that there'll at most one module and it'll be ERM // } } @@ -510,7 +512,7 @@ void CClient::newGame( CConnection *con, StartInfo *si ) void CClient::serialize(COSer & h, const int version) { assert(h.saving); - h & hotSeat; + h & hotSeat; { ui8 players = playerint.size(); h & players; @@ -520,7 +522,7 @@ void CClient::serialize(COSer & h, const int version) LOG_TRACE_PARAMS(logGlobal, "Saving player %s interface", i->first); assert(i->first == i->second->playerID); h & i->first & i->second->dllName & i->second->human; - i->second->saveGame(h, version); + i->second->saveGame(h, version); } } } @@ -536,7 +538,7 @@ void CClient::serialize(CISer & h, const int version) for(int i=0; i < players; i++) { std::string dllname; - PlayerColor pid; + PlayerColor pid; bool isHuman = false; h & pid & dllname & isHuman; @@ -548,7 +550,7 @@ void CClient::serialize(CISer & h, const int version) if(pid == PlayerColor::NEUTRAL) { installNewBattleInterface(CDynLibHandler::getNewBattleAI(dllname), pid); - //TODO? consider serialization + //TODO? consider serialization continue; } else @@ -589,7 +591,7 @@ void CClient::serialize(COSer & h, const int version, const std::setfirst); assert(i->first == i->second->playerID); h & i->first & i->second->dllName & i->second->human; - i->second->saveGame(h, version); + i->second->saveGame(h, version); } } } @@ -605,7 +607,7 @@ void CClient::serialize(CISer & h, const int version, const std::setloadGame(h, version); + nInt->loadGame(h, version); } if(playerIDs.count(PlayerColor::NEUTRAL)) @@ -714,7 +716,7 @@ void CClient::battleStarted(const BattleInfo * info) { for(auto &battleCb : battleCallbacks) { - if(vstd::contains_if(info->sides, [&](const SideInBattle& side) {return side.color == battleCb.first; }) + if(vstd::contains_if(info->sides, [&](const SideInBattle& side) {return side.color == battleCb.first; }) || battleCb.first >= PlayerColor::PLAYER_LIMIT) { battleCb.second->setBattle(info); @@ -742,7 +744,7 @@ void CClient::battleStarted(const BattleInfo * info) { boost::unique_lock un(*LOCPLINT->pim); auto bi = new CBattleInterface(leftSide.armyObject, rightSide.armyObject, leftSide.hero, rightSide.hero, - Rect((screen->w - 800)/2, + Rect((screen->w - 800)/2, (screen->h - 600)/2, 800, 600), att, def); GH.pushInt(bi); @@ -805,7 +807,7 @@ void CClient::commenceTacticPhaseForInt(std::shared_ptr ba catch(...) { handleException(); - } + } } void CClient::invalidatePaths() @@ -889,7 +891,7 @@ void CClient::installNewBattleInterface(std::shared_ptr ba boost::unique_lock un(*LOCPLINT->pim); PlayerColor colorUsed = color.get_value_or(PlayerColor::UNFLAGGABLE); - if(!color) + if(!color) privilagedBattleEventReceivers.push_back(battleInterface); battleints[colorUsed] = battleInterface; @@ -961,7 +963,7 @@ CConnection * CServerHandler::connectToServer() #endif th.update(); //put breakpoint here to attach to server before it does something stupid - + CConnection *ret = justConnectToServer(settings["server"]["server"].String(), port); if(verbose) @@ -1033,7 +1035,7 @@ CConnection * CServerHandler::justConnectToServer(const std::string &host, const try { logNetwork->infoStream() << "Establishing connection..."; - ret = new CConnection( host.size() ? host : settings["server"]["server"].String(), + ret = new CConnection( host.size() ? host : settings["server"]["server"].String(), realPort, NAME); } diff --git a/lib/mapObjects/MiscObjects.cpp b/lib/mapObjects/MiscObjects.cpp index 1889dacd8..28bfdb09f 100644 --- a/lib/mapObjects/MiscObjects.cpp +++ b/lib/mapObjects/MiscObjects.cpp @@ -1867,6 +1867,12 @@ void CGObelisk::initObj() obeliskCount++; } +void CGObelisk::reset() +{ + obeliskCount = 0; + visited.clear(); +} + std::string CGObelisk::getHoverText(PlayerColor player) const { return getObjectName() + " " + visitedTxt(wasVisited(player)); diff --git a/lib/mapObjects/MiscObjects.h b/lib/mapObjects/MiscObjects.h index de358318d..5cc9f379f 100644 --- a/lib/mapObjects/MiscObjects.h +++ b/lib/mapObjects/MiscObjects.h @@ -460,6 +460,7 @@ public: void onHeroVisit(const CGHeroInstance * h) const override; void initObj() override; std::string getHoverText(PlayerColor player) const override; + static void reset(); template void serialize(Handler &h, const int version) {