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.
This commit is contained in:
parent
ac7a588632
commit
926106cf8c
8 changed files with 29 additions and 32 deletions
|
@ -44,7 +44,7 @@ void Player::Init(LuaState &lua)
|
||||||
"guid", sol::readonly_property(&Player::getGUID),
|
"guid", sol::readonly_property(&Player::getGUID),
|
||||||
|
|
||||||
"name", sol::property(&Player::getName, &Player::setName),
|
"name", sol::property(&Player::getName, &Player::setName),
|
||||||
"setCharGenStage", &Player::setCharGenStage,
|
"setCharGenStages", &Player::setCharGenStages,
|
||||||
"isMale", &Player::isMale,
|
"isMale", &Player::isMale,
|
||||||
"setIsMake", &Player::setIsMale,
|
"setIsMake", &Player::setIsMale,
|
||||||
"level", sol::property(&Player::getLevel, &Player::setLevel),
|
"level", sol::property(&Player::getLevel, &Player::setLevel),
|
||||||
|
@ -314,10 +314,11 @@ std::string Player::getName()
|
||||||
return npc.mName;
|
return npc.mName;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::setCharGenStage(int start, int end)
|
void Player::setCharGenStages(int currentStage, int endStage)
|
||||||
{
|
{
|
||||||
charGenStage.current = start;
|
charGenState.currentStage = currentStage;
|
||||||
charGenStage.end = end;
|
charGenState.endStage = endStage;
|
||||||
|
charGenState.isFinished = false;
|
||||||
|
|
||||||
auto packet = mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_CHARGEN);
|
auto packet = mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_CHARGEN);
|
||||||
packet->setPlayer(this);
|
packet->setPlayer(this);
|
||||||
|
|
|
@ -80,7 +80,7 @@ public:
|
||||||
|
|
||||||
void setName(const std::string &name);
|
void setName(const std::string &name);
|
||||||
std::string getName();
|
std::string getName();
|
||||||
void setCharGenStage(int start, int end);
|
void setCharGenStages(int currentStage, int endStage);
|
||||||
void message(const std::string &message, bool toAll = false);
|
void message(const std::string &message, bool toAll = false);
|
||||||
bool isMale() const;
|
bool isMale() const;
|
||||||
void setIsMale(bool male);
|
void setIsMale(bool male);
|
||||||
|
|
|
@ -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)
|
||||||
Networking::get().getState().getEventCtrl().Call<CoreEvent::ON_PLAYER_ENDCHARGEN>(player);
|
Networking::get().getState().getEventCtrl().Call<CoreEvent::ON_PLAYER_ENDCHARGEN>(player);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -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;
|
||||||
|
|
||||||
consoleAllowed = false;
|
consoleAllowed = false;
|
||||||
difficulty = 0;
|
difficulty = 0;
|
||||||
|
@ -104,26 +105,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);
|
||||||
|
@ -143,14 +140,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();
|
||||||
|
@ -163,7 +160,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);
|
||||||
|
@ -177,8 +174,8 @@ bool LocalPlayer::charGenThread()
|
||||||
|
|
||||||
sendCellStates();
|
sendCellStates();
|
||||||
|
|
||||||
// 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;
|
||||||
|
@ -186,7 +183,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)
|
||||||
|
|
|
@ -21,8 +21,7 @@ namespace mwmp
|
||||||
|
|
||||||
void update();
|
void update();
|
||||||
|
|
||||||
void charGen(int stageFirst, int stageEnd);
|
bool processCharGen(); // return true if CGStage::current == CGStage::end
|
||||||
bool charGenThread(); // return true if CGStage::current == CGStage::end
|
|
||||||
bool hasFinishedCharGen();
|
bool hasFinishedCharGen();
|
||||||
|
|
||||||
void updateStatsDynamic(bool forceUpdate = false);
|
void updateStatsDynamic(bool forceUpdate = false);
|
||||||
|
|
|
@ -212,8 +212,7 @@ void Main::frame(float dt)
|
||||||
|
|
||||||
void Main::updateWorld(float dt) const
|
void Main::updateWorld(float dt) const
|
||||||
{
|
{
|
||||||
|
if (!mLocalPlayer->processCharGen())
|
||||||
if (!mLocalPlayer->charGenThread())
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
static bool init = true;
|
static bool init = true;
|
||||||
|
|
|
@ -154,9 +154,10 @@ namespace mwmp
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
struct CGStage
|
struct CharGenState
|
||||||
{
|
{
|
||||||
int current, end;
|
int currentStage, endStage;
|
||||||
|
bool isFinished;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct GUIMessageBox
|
struct GUIMessageBox
|
||||||
|
@ -227,7 +228,7 @@ namespace mwmp
|
||||||
ESM::Class charClass;
|
ESM::Class charClass;
|
||||||
std::string birthsign;
|
std::string birthsign;
|
||||||
std::string chatMessage;
|
std::string chatMessage;
|
||||||
CGStage charGenStage;
|
CharGenState charGenState;
|
||||||
std::string passw;
|
std::string passw;
|
||||||
|
|
||||||
bool isWerewolf;
|
bool isWerewolf;
|
||||||
|
|
|
@ -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