mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-12 02:28:11 +02:00
Reset obelisks upon game end
Otherwise, the static variables are preserved and lead to wrong values in next new game.
This commit is contained in:
parent
1a2cd36df8
commit
e8db456beb
@ -59,8 +59,8 @@ template <typename T> class CApplyOnCL;
|
|||||||
class CBaseForCLApply
|
class CBaseForCLApply
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual void applyOnClAfter(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 void applyOnClBefore(CClient *cl, void *pack) const =0;
|
||||||
virtual ~CBaseForCLApply(){}
|
virtual ~CBaseForCLApply(){}
|
||||||
|
|
||||||
template<typename U> static CBaseForCLApply *getApplier(const U * t=nullptr)
|
template<typename U> static CBaseForCLApply *getApplier(const U * t=nullptr)
|
||||||
@ -144,7 +144,7 @@ void CClient::waitForMoveAndSend(PlayerColor color)
|
|||||||
{
|
{
|
||||||
logNetwork->traceStream() << "Send battle action to server: " << ba;
|
logNetwork->traceStream() << "Send battle action to server: " << ba;
|
||||||
MakeAction temp_action(ba);
|
MakeAction temp_action(ba);
|
||||||
sendRequest(&temp_action, color);
|
sendRequest(&temp_action, color);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -169,8 +169,8 @@ void CClient::run()
|
|||||||
while(!terminate)
|
while(!terminate)
|
||||||
{
|
{
|
||||||
CPack *pack = serv->retreivePack(); //get the package from the server
|
CPack *pack = serv->retreivePack(); //get the package from the server
|
||||||
|
|
||||||
if (terminate)
|
if (terminate)
|
||||||
{
|
{
|
||||||
vstd::clear_pointer(pack);
|
vstd::clear_pointer(pack);
|
||||||
break;
|
break;
|
||||||
@ -178,10 +178,10 @@ void CClient::run()
|
|||||||
|
|
||||||
handlePack(pack);
|
handlePack(pack);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//catch only asio exceptions
|
//catch only asio exceptions
|
||||||
catch (const boost::system::system_error& e)
|
catch (const boost::system::system_error& e)
|
||||||
{
|
{
|
||||||
logNetwork->errorStream() << "Lost connection to server, ending listening thread!";
|
logNetwork->errorStream() << "Lost connection to server, ending listening thread!";
|
||||||
logNetwork->errorStream() << e.what();
|
logNetwork->errorStream() << e.what();
|
||||||
if(!terminate) //rethrow (-> boom!) only if closing connection was unexpected
|
if(!terminate) //rethrow (-> boom!) only if closing connection was unexpected
|
||||||
@ -219,18 +219,20 @@ void CClient::endGame( bool closeConnection /*= true*/ )
|
|||||||
GH.curInt = nullptr;
|
GH.curInt = nullptr;
|
||||||
{
|
{
|
||||||
boost::unique_lock<boost::recursive_mutex> un(*LOCPLINT->pim);
|
boost::unique_lock<boost::recursive_mutex> un(*LOCPLINT->pim);
|
||||||
logNetwork->infoStream() << "Ending current game!";
|
logNetwork->infoStream() << "Ending current game!";
|
||||||
if(GH.topInt())
|
if(GH.topInt())
|
||||||
|
{
|
||||||
GH.topInt()->deactivate();
|
GH.topInt()->deactivate();
|
||||||
|
}
|
||||||
GH.listInt.clear();
|
GH.listInt.clear();
|
||||||
GH.objsToBlit.clear();
|
GH.objsToBlit.clear();
|
||||||
GH.statusbar = nullptr;
|
GH.statusbar = nullptr;
|
||||||
logNetwork->infoStream() << "Removed GUI.";
|
logNetwork->infoStream() << "Removed GUI.";
|
||||||
|
|
||||||
vstd::clear_pointer(const_cast<CGameInfo*>(CGI)->mh);
|
vstd::clear_pointer(const_cast<CGameInfo*>(CGI)->mh);
|
||||||
vstd::clear_pointer(gs);
|
vstd::clear_pointer(gs);
|
||||||
|
|
||||||
logNetwork->infoStream() << "Deleted mapHandler and gameState.";
|
logNetwork->infoStream() << "Deleted mapHandler and gameState.";
|
||||||
LOCPLINT = nullptr;
|
LOCPLINT = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -238,9 +240,9 @@ void CClient::endGame( bool closeConnection /*= true*/ )
|
|||||||
battleints.clear();
|
battleints.clear();
|
||||||
callbacks.clear();
|
callbacks.clear();
|
||||||
battleCallbacks.clear();
|
battleCallbacks.clear();
|
||||||
logNetwork->infoStream() << "Deleted playerInts.";
|
CGObelisk::reset();
|
||||||
|
logNetwork->infoStream() << "Deleted playerInts.";
|
||||||
logNetwork->infoStream() << "Client stopped.";
|
logNetwork->infoStream() << "Client stopped.";
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 1
|
#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 << ui8(3) << ui8(loadNumPlayers); //load game; one client if single-player
|
||||||
*serv << fname;
|
*serv << fname;
|
||||||
*serv >> pom8;
|
*serv >> pom8;
|
||||||
if(pom8)
|
if(pom8)
|
||||||
throw std::runtime_error("Server cannot open the savegame!");
|
throw std::runtime_error("Server cannot open the savegame!");
|
||||||
else
|
else
|
||||||
logNetwork->infoStream() << "Server opened savegame properly.";
|
logNetwork->infoStream() << "Server opened savegame properly.";
|
||||||
@ -376,7 +378,7 @@ void CClient::newGame( CConnection *con, StartInfo *si )
|
|||||||
{
|
{
|
||||||
enum {SINGLE, HOST, GUEST} networkMode = SINGLE;
|
enum {SINGLE, HOST, GUEST} networkMode = SINGLE;
|
||||||
|
|
||||||
if (con == nullptr)
|
if (con == nullptr)
|
||||||
{
|
{
|
||||||
CServerHandler sh;
|
CServerHandler sh;
|
||||||
serv = sh.connectToServer();
|
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;
|
logNetwork->infoStream() << boost::format("Player %s will be lead by %s") % color % AiToGive;
|
||||||
installNewPlayerInterface(CDynLibHandler::getNewAI(AiToGive), color);
|
installNewPlayerInterface(CDynLibHandler::getNewAI(AiToGive), color);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
installNewPlayerInterface(std::make_shared<CPlayerInterface>(color), color);
|
installNewPlayerInterface(std::make_shared<CPlayerInterface>(color), color);
|
||||||
humanPlayers++;
|
humanPlayers++;
|
||||||
@ -502,7 +504,7 @@ void CClient::newGame( CConnection *con, StartInfo *si )
|
|||||||
// nm->giveActionCB(this);
|
// nm->giveActionCB(this);
|
||||||
// nm->giveInfoCB(this);
|
// nm->giveInfoCB(this);
|
||||||
// nm->init();
|
// nm->init();
|
||||||
//
|
//
|
||||||
// erm = nm; //something tells me that there'll at most one module and it'll be ERM
|
// 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)
|
void CClient::serialize(COSer & h, const int version)
|
||||||
{
|
{
|
||||||
assert(h.saving);
|
assert(h.saving);
|
||||||
h & hotSeat;
|
h & hotSeat;
|
||||||
{
|
{
|
||||||
ui8 players = playerint.size();
|
ui8 players = playerint.size();
|
||||||
h & players;
|
h & players;
|
||||||
@ -520,7 +522,7 @@ void CClient::serialize(COSer & h, const int version)
|
|||||||
LOG_TRACE_PARAMS(logGlobal, "Saving player %s interface", i->first);
|
LOG_TRACE_PARAMS(logGlobal, "Saving player %s interface", i->first);
|
||||||
assert(i->first == i->second->playerID);
|
assert(i->first == i->second->playerID);
|
||||||
h & i->first & i->second->dllName & i->second->human;
|
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++)
|
for(int i=0; i < players; i++)
|
||||||
{
|
{
|
||||||
std::string dllname;
|
std::string dllname;
|
||||||
PlayerColor pid;
|
PlayerColor pid;
|
||||||
bool isHuman = false;
|
bool isHuman = false;
|
||||||
|
|
||||||
h & pid & dllname & isHuman;
|
h & pid & dllname & isHuman;
|
||||||
@ -548,7 +550,7 @@ void CClient::serialize(CISer & h, const int version)
|
|||||||
if(pid == PlayerColor::NEUTRAL)
|
if(pid == PlayerColor::NEUTRAL)
|
||||||
{
|
{
|
||||||
installNewBattleInterface(CDynLibHandler::getNewBattleAI(dllname), pid);
|
installNewBattleInterface(CDynLibHandler::getNewBattleAI(dllname), pid);
|
||||||
//TODO? consider serialization
|
//TODO? consider serialization
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -589,7 +591,7 @@ void CClient::serialize(COSer & h, const int version, const std::set<PlayerColor
|
|||||||
LOG_TRACE_PARAMS(logGlobal, "Saving player %s interface", i->first);
|
LOG_TRACE_PARAMS(logGlobal, "Saving player %s interface", i->first);
|
||||||
assert(i->first == i->second->playerID);
|
assert(i->first == i->second->playerID);
|
||||||
h & i->first & i->second->dllName & i->second->human;
|
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::set<PlayerColor
|
|||||||
for(int i=0; i < players; i++)
|
for(int i=0; i < players; i++)
|
||||||
{
|
{
|
||||||
std::string dllname;
|
std::string dllname;
|
||||||
PlayerColor pid;
|
PlayerColor pid;
|
||||||
bool isHuman = false;
|
bool isHuman = false;
|
||||||
|
|
||||||
h & pid & dllname & isHuman;
|
h & pid & dllname & isHuman;
|
||||||
@ -618,7 +620,7 @@ void CClient::serialize(CISer & h, const int version, const std::set<PlayerColor
|
|||||||
{
|
{
|
||||||
if(playerIDs.count(pid))
|
if(playerIDs.count(pid))
|
||||||
installNewBattleInterface(CDynLibHandler::getNewBattleAI(dllname), pid);
|
installNewBattleInterface(CDynLibHandler::getNewBattleAI(dllname), pid);
|
||||||
//TODO? consider serialization
|
//TODO? consider serialization
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -640,7 +642,7 @@ void CClient::serialize(CISer & h, const int version, const std::set<PlayerColor
|
|||||||
if(playerIDs.count(pid))
|
if(playerIDs.count(pid))
|
||||||
installNewPlayerInterface(nInt, pid);
|
installNewPlayerInterface(nInt, pid);
|
||||||
|
|
||||||
nInt->loadGame(h, version);
|
nInt->loadGame(h, version);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(playerIDs.count(PlayerColor::NEUTRAL))
|
if(playerIDs.count(PlayerColor::NEUTRAL))
|
||||||
@ -714,7 +716,7 @@ void CClient::battleStarted(const BattleInfo * info)
|
|||||||
{
|
{
|
||||||
for(auto &battleCb : battleCallbacks)
|
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.first >= PlayerColor::PLAYER_LIMIT)
|
||||||
{
|
{
|
||||||
battleCb.second->setBattle(info);
|
battleCb.second->setBattle(info);
|
||||||
@ -742,7 +744,7 @@ void CClient::battleStarted(const BattleInfo * info)
|
|||||||
{
|
{
|
||||||
boost::unique_lock<boost::recursive_mutex> un(*LOCPLINT->pim);
|
boost::unique_lock<boost::recursive_mutex> un(*LOCPLINT->pim);
|
||||||
auto bi = new CBattleInterface(leftSide.armyObject, rightSide.armyObject, leftSide.hero, rightSide.hero,
|
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);
|
(screen->h - 600)/2, 800, 600), att, def);
|
||||||
|
|
||||||
GH.pushInt(bi);
|
GH.pushInt(bi);
|
||||||
@ -805,7 +807,7 @@ void CClient::commenceTacticPhaseForInt(std::shared_ptr<CBattleGameInterface> ba
|
|||||||
catch(...)
|
catch(...)
|
||||||
{
|
{
|
||||||
handleException();
|
handleException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CClient::invalidatePaths()
|
void CClient::invalidatePaths()
|
||||||
@ -889,7 +891,7 @@ void CClient::installNewBattleInterface(std::shared_ptr<CBattleGameInterface> ba
|
|||||||
boost::unique_lock<boost::recursive_mutex> un(*LOCPLINT->pim);
|
boost::unique_lock<boost::recursive_mutex> un(*LOCPLINT->pim);
|
||||||
PlayerColor colorUsed = color.get_value_or(PlayerColor::UNFLAGGABLE);
|
PlayerColor colorUsed = color.get_value_or(PlayerColor::UNFLAGGABLE);
|
||||||
|
|
||||||
if(!color)
|
if(!color)
|
||||||
privilagedBattleEventReceivers.push_back(battleInterface);
|
privilagedBattleEventReceivers.push_back(battleInterface);
|
||||||
|
|
||||||
battleints[colorUsed] = battleInterface;
|
battleints[colorUsed] = battleInterface;
|
||||||
@ -961,7 +963,7 @@ CConnection * CServerHandler::connectToServer()
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
th.update(); //put breakpoint here to attach to server before it does something stupid
|
th.update(); //put breakpoint here to attach to server before it does something stupid
|
||||||
|
|
||||||
CConnection *ret = justConnectToServer(settings["server"]["server"].String(), port);
|
CConnection *ret = justConnectToServer(settings["server"]["server"].String(), port);
|
||||||
|
|
||||||
if(verbose)
|
if(verbose)
|
||||||
@ -1033,7 +1035,7 @@ CConnection * CServerHandler::justConnectToServer(const std::string &host, const
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
logNetwork->infoStream() << "Establishing connection...";
|
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,
|
realPort,
|
||||||
NAME);
|
NAME);
|
||||||
}
|
}
|
||||||
|
@ -1867,6 +1867,12 @@ void CGObelisk::initObj()
|
|||||||
obeliskCount++;
|
obeliskCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CGObelisk::reset()
|
||||||
|
{
|
||||||
|
obeliskCount = 0;
|
||||||
|
visited.clear();
|
||||||
|
}
|
||||||
|
|
||||||
std::string CGObelisk::getHoverText(PlayerColor player) const
|
std::string CGObelisk::getHoverText(PlayerColor player) const
|
||||||
{
|
{
|
||||||
return getObjectName() + " " + visitedTxt(wasVisited(player));
|
return getObjectName() + " " + visitedTxt(wasVisited(player));
|
||||||
|
@ -460,6 +460,7 @@ public:
|
|||||||
void onHeroVisit(const CGHeroInstance * h) const override;
|
void onHeroVisit(const CGHeroInstance * h) const override;
|
||||||
void initObj() override;
|
void initObj() override;
|
||||||
std::string getHoverText(PlayerColor player) const override;
|
std::string getHoverText(PlayerColor player) const override;
|
||||||
|
static void reset();
|
||||||
|
|
||||||
template <typename Handler> void serialize(Handler &h, const int version)
|
template <typename Handler> void serialize(Handler &h, const int version)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user