forked from mirror/openmw-tes3mp
[General] Rework CharGen slightly for clarity purposes
Previously, charGenStage.end was doing double duty as both the variable indicating the number of CharGen stages and – when set to 0 – the variable indicating that CharGen was over. The latter role is now filled by a new boolean.
(cherry picked from commit 926106cf8c
)
This commit is contained in:
parent
9d46de88e0
commit
28f1c1b0d3
8 changed files with 30 additions and 36 deletions
|
@ -476,13 +476,14 @@ void StatsFunctions::SetBounty(unsigned short pid, int value) noexcept
|
||||||
player->npcStats.mBounty = value;
|
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;
|
Player *player;
|
||||||
GET_PLAYER(pid, player,);
|
GET_PLAYER(pid, player,);
|
||||||
|
|
||||||
player->charGenStage.current = current;
|
player->charGenState.currentStage = currentStage;
|
||||||
player->charGenStage.end = end;
|
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)->setPlayer(player);
|
||||||
mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_CHARGEN)->Send(false);
|
mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_CHARGEN)->Send(false);
|
||||||
|
|
|
@ -555,11 +555,11 @@ public:
|
||||||
* This is used to repeat part of character generation or to only go through part of it.
|
* This is used to repeat part of character generation or to only go through part of it.
|
||||||
*
|
*
|
||||||
* \param pid The player ID.
|
* \param pid The player ID.
|
||||||
* \param current The current stage.
|
* \param currentStage The new current stage.
|
||||||
* \param end The ending stage.
|
* \param endStage The new ending stage.
|
||||||
* \return void
|
* \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,
|
* \brief Send a PlayerBaseInfo packet with a player's name, race, head mesh,
|
||||||
|
|
|
@ -21,7 +21,7 @@ namespace mwmp
|
||||||
{
|
{
|
||||||
DEBUG_PRINTF(strPacketID.c_str());
|
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<Script::CallbackIdentity("OnPlayerEndCharGen")>(player.getId());
|
Script::Call<Script::CallbackIdentity("OnPlayerEndCharGen")>(player.getId());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -44,8 +44,9 @@ using namespace std;
|
||||||
|
|
||||||
LocalPlayer::LocalPlayer()
|
LocalPlayer::LocalPlayer()
|
||||||
{
|
{
|
||||||
charGenStage.current = 0;
|
charGenState.currentStage = 0;
|
||||||
charGenStage.end = 1;
|
charGenState.endStage = 1;
|
||||||
|
charGenState.isFinished = false;
|
||||||
|
|
||||||
difficulty = 0;
|
difficulty = 0;
|
||||||
enforcedLogLevel = -1;
|
enforcedLogLevel = -1;
|
||||||
|
@ -113,26 +114,22 @@ void LocalPlayer::update()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocalPlayer::charGen(int stageFirst, int stageEnd)
|
bool LocalPlayer::processCharGen()
|
||||||
{
|
|
||||||
charGenStage.current = stageFirst;
|
|
||||||
charGenStage.end = stageEnd;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool LocalPlayer::charGenThread()
|
|
||||||
{
|
{
|
||||||
MWBase::WindowManager *windowManager = MWBase::Environment::get().getWindowManager();
|
MWBase::WindowManager *windowManager = MWBase::Environment::get().getWindowManager();
|
||||||
|
|
||||||
// If we haven't finished CharGen and we're in a menu, it must be
|
// 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
|
// 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;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// If the current stage of CharGen is not the last one,
|
// If the current stage of CharGen is not the last one,
|
||||||
// move to the next 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:
|
case 0:
|
||||||
windowManager->pushGuiMode(MWGui::GM_Name);
|
windowManager->pushGuiMode(MWGui::GM_Name);
|
||||||
|
@ -152,14 +149,14 @@ bool LocalPlayer::charGenThread()
|
||||||
}
|
}
|
||||||
getNetworking()->getPlayerPacket(ID_PLAYER_CHARGEN)->setPlayer(this);
|
getNetworking()->getPlayerPacket(ID_PLAYER_CHARGEN)->setPlayer(this);
|
||||||
getNetworking()->getPlayerPacket(ID_PLAYER_CHARGEN)->Send();
|
getNetworking()->getPlayerPacket(ID_PLAYER_CHARGEN)->Send();
|
||||||
charGenStage.current++;
|
charGenState.currentStage++;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we've reached the last stage of CharGen, send the
|
// If we've reached the last stage of CharGen, send the
|
||||||
// corresponding packets and mark CharGen as finished
|
// corresponding packets and mark CharGen as finished
|
||||||
else if (charGenStage.end != 0)
|
else if (!charGenState.isFinished)
|
||||||
{
|
{
|
||||||
MWBase::World *world = MWBase::Environment::get().getWorld();
|
MWBase::World *world = MWBase::Environment::get().getWorld();
|
||||||
MWWorld::Ptr ptrPlayer = world->getPlayerPtr();
|
MWWorld::Ptr ptrPlayer = world->getPlayerPtr();
|
||||||
|
@ -172,7 +169,7 @@ bool LocalPlayer::charGenThread()
|
||||||
|
|
||||||
// Send stats packets if this is the 2nd round of CharGen that
|
// Send stats packets if this is the 2nd round of CharGen that
|
||||||
// only happens for new characters
|
// only happens for new characters
|
||||||
if (charGenStage.end != 1)
|
if (charGenState.endStage != 1)
|
||||||
{
|
{
|
||||||
updateStatsDynamic(true);
|
updateStatsDynamic(true);
|
||||||
updateAttributes(true);
|
updateAttributes(true);
|
||||||
|
@ -184,8 +181,8 @@ bool LocalPlayer::charGenThread()
|
||||||
getNetworking()->getPlayerPacket(ID_PLAYER_CHARGEN)->Send();
|
getNetworking()->getPlayerPacket(ID_PLAYER_CHARGEN)->Send();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the last stage variable to 0 to indicate that CharGen is finished
|
// Mark character generation as finished until overridden by a new ID_PLAYER_CHARGEN packet
|
||||||
charGenStage.end = 0;
|
charGenState.isFinished = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -193,7 +190,7 @@ bool LocalPlayer::charGenThread()
|
||||||
|
|
||||||
bool LocalPlayer::hasFinishedCharGen()
|
bool LocalPlayer::hasFinishedCharGen()
|
||||||
{
|
{
|
||||||
return charGenStage.end == 0;
|
return charGenState.isFinished;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocalPlayer::updateStatsDynamic(bool forceUpdate)
|
void LocalPlayer::updateStatsDynamic(bool forceUpdate)
|
||||||
|
|
|
@ -1,7 +1,3 @@
|
||||||
//
|
|
||||||
// Created by koncord on 14.01.16.
|
|
||||||
//
|
|
||||||
|
|
||||||
#ifndef OPENMW_LOCALPLAYER_HPP
|
#ifndef OPENMW_LOCALPLAYER_HPP
|
||||||
#define OPENMW_LOCALPLAYER_HPP
|
#define OPENMW_LOCALPLAYER_HPP
|
||||||
|
|
||||||
|
@ -21,8 +17,7 @@ namespace mwmp
|
||||||
|
|
||||||
void update();
|
void update();
|
||||||
|
|
||||||
void charGen(int stageFirst, int stageEnd);
|
bool processCharGen();
|
||||||
bool charGenThread(); // return true if CGStage::current == CGStage::end
|
|
||||||
bool hasFinishedCharGen();
|
bool hasFinishedCharGen();
|
||||||
|
|
||||||
void updateStatsDynamic(bool forceUpdate = false);
|
void updateStatsDynamic(bool forceUpdate = false);
|
||||||
|
|
|
@ -213,7 +213,7 @@ void Main::frame(float dt)
|
||||||
void Main::updateWorld(float dt) const
|
void Main::updateWorld(float dt) const
|
||||||
{
|
{
|
||||||
|
|
||||||
if (!mLocalPlayer->charGenThread())
|
if (!mLocalPlayer->processCharGen())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
static bool init = true;
|
static bool init = true;
|
||||||
|
|
|
@ -195,9 +195,10 @@ namespace mwmp
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
struct CGStage
|
struct CharGenState
|
||||||
{
|
{
|
||||||
int current, end;
|
int currentStage, endStage;
|
||||||
|
bool isFinished;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct GUIMessageBox
|
struct GUIMessageBox
|
||||||
|
@ -282,7 +283,7 @@ namespace mwmp
|
||||||
Attack attack;
|
Attack attack;
|
||||||
std::string birthsign;
|
std::string birthsign;
|
||||||
std::string chatMessage;
|
std::string chatMessage;
|
||||||
CGStage charGenStage;
|
CharGenState charGenState;
|
||||||
std::string passw;
|
std::string passw;
|
||||||
|
|
||||||
std::string sound;
|
std::string sound;
|
||||||
|
|
|
@ -14,6 +14,6 @@ void mwmp::PacketPlayerCharGen::Packet(RakNet::BitStream *bs, bool send)
|
||||||
{
|
{
|
||||||
PlayerPacket::Packet(bs, send);
|
PlayerPacket::Packet(bs, send);
|
||||||
|
|
||||||
RW(player->charGenStage, send);
|
RW(player->charGenState, send);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue