diff --git a/apps/openmw-mp/Script/Functions/Stats.cpp b/apps/openmw-mp/Script/Functions/Stats.cpp index 9fa4b5dd0..00d271bc9 100644 --- a/apps/openmw-mp/Script/Functions/Stats.cpp +++ b/apps/openmw-mp/Script/Functions/Stats.cpp @@ -476,13 +476,14 @@ void StatsFunctions::SetBounty(unsigned short pid, int value) noexcept player->npcStats.mBounty = value; } -void StatsFunctions::SetCharGenStage(unsigned short pid, int current, int end) noexcept +void StatsFunctions::SetCharGenStage(unsigned short pid, int currentStage, int endStage) noexcept { Player *player; GET_PLAYER(pid, player,); - player->charGenStage.current = current; - player->charGenStage.end = end; + player->charGenState.currentStage = currentStage; + player->charGenState.endStage = endStage; + player->charGenState.isFinished = false; mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_CHARGEN)->setPlayer(player); mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_CHARGEN)->Send(false); diff --git a/apps/openmw-mp/Script/Functions/Stats.hpp b/apps/openmw-mp/Script/Functions/Stats.hpp index 2efda5cf4..678caa58a 100644 --- a/apps/openmw-mp/Script/Functions/Stats.hpp +++ b/apps/openmw-mp/Script/Functions/Stats.hpp @@ -555,11 +555,11 @@ public: * This is used to repeat part of character generation or to only go through part of it. * * \param pid The player ID. - * \param current The current stage. - * \param end The ending stage. + * \param currentStage The new current stage. + * \param endStage The new ending stage. * \return void */ - static void SetCharGenStage(unsigned short pid, int current, int end) noexcept; + static void SetCharGenStage(unsigned short pid, int currentStage, int endStage) noexcept; /** * \brief Send a PlayerBaseInfo packet with a player's name, race, head mesh, diff --git a/apps/openmw-mp/processors/player/ProcessorPlayerCharGen.hpp b/apps/openmw-mp/processors/player/ProcessorPlayerCharGen.hpp index f4eca4e70..20410bd4e 100644 --- a/apps/openmw-mp/processors/player/ProcessorPlayerCharGen.hpp +++ b/apps/openmw-mp/processors/player/ProcessorPlayerCharGen.hpp @@ -21,7 +21,7 @@ namespace mwmp { DEBUG_PRINTF(strPacketID.c_str()); - if (player.charGenStage.current == player.charGenStage.end && player.charGenStage.current != 0) + if (player.charGenState.currentStage == player.charGenState.endStage) Script::Call(player.getId()); } }; diff --git a/apps/openmw/mwmp/LocalPlayer.cpp b/apps/openmw/mwmp/LocalPlayer.cpp index b723e487e..b134fc27e 100644 --- a/apps/openmw/mwmp/LocalPlayer.cpp +++ b/apps/openmw/mwmp/LocalPlayer.cpp @@ -44,8 +44,9 @@ using namespace std; LocalPlayer::LocalPlayer() { - charGenStage.current = 0; - charGenStage.end = 1; + charGenState.currentStage = 0; + charGenState.endStage = 1; + charGenState.isFinished = false; difficulty = 0; enforcedLogLevel = -1; @@ -113,26 +114,22 @@ void LocalPlayer::update() } } -void LocalPlayer::charGen(int stageFirst, int stageEnd) -{ - charGenStage.current = stageFirst; - charGenStage.end = stageEnd; -} - -bool LocalPlayer::charGenThread() +bool LocalPlayer::processCharGen() { MWBase::WindowManager *windowManager = MWBase::Environment::get().getWindowManager(); // If we haven't finished CharGen and we're in a menu, it must be // one of the CharGen menus, so go no further until it's closed - if (windowManager->isGuiMode() && charGenStage.end != 0) + if (windowManager->isGuiMode() && !charGenState.isFinished) + { return false; + } // If the current stage of CharGen is not the last one, // move to the next one - else if (charGenStage.current < charGenStage.end) + else if (charGenState.currentStage < charGenState.endStage) { - switch (charGenStage.current) + switch (charGenState.currentStage) { case 0: windowManager->pushGuiMode(MWGui::GM_Name); @@ -152,14 +149,14 @@ bool LocalPlayer::charGenThread() } getNetworking()->getPlayerPacket(ID_PLAYER_CHARGEN)->setPlayer(this); getNetworking()->getPlayerPacket(ID_PLAYER_CHARGEN)->Send(); - charGenStage.current++; + charGenState.currentStage++; return false; } // If we've reached the last stage of CharGen, send the // corresponding packets and mark CharGen as finished - else if (charGenStage.end != 0) + else if (!charGenState.isFinished) { MWBase::World *world = MWBase::Environment::get().getWorld(); MWWorld::Ptr ptrPlayer = world->getPlayerPtr(); @@ -172,7 +169,7 @@ bool LocalPlayer::charGenThread() // Send stats packets if this is the 2nd round of CharGen that // only happens for new characters - if (charGenStage.end != 1) + if (charGenState.endStage != 1) { updateStatsDynamic(true); updateAttributes(true); @@ -184,8 +181,8 @@ bool LocalPlayer::charGenThread() getNetworking()->getPlayerPacket(ID_PLAYER_CHARGEN)->Send(); } - // Set the last stage variable to 0 to indicate that CharGen is finished - charGenStage.end = 0; + // Mark character generation as finished until overridden by a new ID_PLAYER_CHARGEN packet + charGenState.isFinished = true; } return true; @@ -193,7 +190,7 @@ bool LocalPlayer::charGenThread() bool LocalPlayer::hasFinishedCharGen() { - return charGenStage.end == 0; + return charGenState.isFinished; } void LocalPlayer::updateStatsDynamic(bool forceUpdate) diff --git a/apps/openmw/mwmp/LocalPlayer.hpp b/apps/openmw/mwmp/LocalPlayer.hpp index 44baea429..0c25f374e 100644 --- a/apps/openmw/mwmp/LocalPlayer.hpp +++ b/apps/openmw/mwmp/LocalPlayer.hpp @@ -1,7 +1,3 @@ -// -// Created by koncord on 14.01.16. -// - #ifndef OPENMW_LOCALPLAYER_HPP #define OPENMW_LOCALPLAYER_HPP @@ -21,8 +17,7 @@ namespace mwmp void update(); - void charGen(int stageFirst, int stageEnd); - bool charGenThread(); // return true if CGStage::current == CGStage::end + bool processCharGen(); bool hasFinishedCharGen(); void updateStatsDynamic(bool forceUpdate = false); diff --git a/apps/openmw/mwmp/Main.cpp b/apps/openmw/mwmp/Main.cpp index 214f550f1..c62d297e0 100644 --- a/apps/openmw/mwmp/Main.cpp +++ b/apps/openmw/mwmp/Main.cpp @@ -213,7 +213,7 @@ void Main::frame(float dt) void Main::updateWorld(float dt) const { - if (!mLocalPlayer->charGenThread()) + if (!mLocalPlayer->processCharGen()) return; static bool init = true; diff --git a/components/openmw-mp/Base/BasePlayer.hpp b/components/openmw-mp/Base/BasePlayer.hpp index 119db0eca..46e42ec6a 100644 --- a/components/openmw-mp/Base/BasePlayer.hpp +++ b/components/openmw-mp/Base/BasePlayer.hpp @@ -195,9 +195,10 @@ namespace mwmp { public: - struct CGStage + struct CharGenState { - int current, end; + int currentStage, endStage; + bool isFinished; }; struct GUIMessageBox @@ -282,7 +283,7 @@ namespace mwmp Attack attack; std::string birthsign; std::string chatMessage; - CGStage charGenStage; + CharGenState charGenState; std::string passw; std::string sound; diff --git a/components/openmw-mp/Packets/Player/PacketPlayerCharGen.cpp b/components/openmw-mp/Packets/Player/PacketPlayerCharGen.cpp index 63bc61deb..1ea695c77 100644 --- a/components/openmw-mp/Packets/Player/PacketPlayerCharGen.cpp +++ b/components/openmw-mp/Packets/Player/PacketPlayerCharGen.cpp @@ -14,6 +14,6 @@ void mwmp::PacketPlayerCharGen::Packet(RakNet::BitStream *bs, bool send) { PlayerPacket::Packet(bs, send); - RW(player->charGenStage, send); + RW(player->charGenState, send); }