[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.
new-script-api
David Cernat 7 years ago
parent ac7a588632
commit 926106cf8c

@ -44,7 +44,7 @@ void Player::Init(LuaState &lua)
"guid", sol::readonly_property(&Player::getGUID),
"name", sol::property(&Player::getName, &Player::setName),
"setCharGenStage", &Player::setCharGenStage,
"setCharGenStages", &Player::setCharGenStages,
"isMale", &Player::isMale,
"setIsMake", &Player::setIsMale,
"level", sol::property(&Player::getLevel, &Player::setLevel),
@ -314,10 +314,11 @@ std::string Player::getName()
return npc.mName;
}
void Player::setCharGenStage(int start, int end)
void Player::setCharGenStages(int currentStage, int endStage)
{
charGenStage.current = start;
charGenStage.end = end;
charGenState.currentStage = currentStage;
charGenState.endStage = endStage;
charGenState.isFinished = false;
auto packet = mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_CHARGEN);
packet->setPlayer(this);

@ -80,7 +80,7 @@ public:
void setName(const std::string &name);
std::string getName();
void setCharGenStage(int start, int end);
void setCharGenStages(int currentStage, int endStage);
void message(const std::string &message, bool toAll = false);
bool isMale() const;
void setIsMale(bool male);

@ -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)
Networking::get().getState().getEventCtrl().Call<CoreEvent::ON_PLAYER_ENDCHARGEN>(player);
}
};

@ -44,8 +44,9 @@ using namespace std;
LocalPlayer::LocalPlayer()
{
charGenStage.current = 0;
charGenStage.end = 1;
charGenState.currentStage = 0;
charGenState.endStage = 1;
charGenState.isFinished = false;
consoleAllowed = false;
difficulty = 0;
@ -104,26 +105,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);
@ -143,14 +140,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();
@ -163,7 +160,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);
@ -177,8 +174,8 @@ bool LocalPlayer::charGenThread()
sendCellStates();
// 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;
@ -186,7 +183,7 @@ bool LocalPlayer::charGenThread()
bool LocalPlayer::hasFinishedCharGen()
{
return charGenStage.end == 0;
return charGenState.isFinished;
}
void LocalPlayer::updateStatsDynamic(bool forceUpdate)

@ -21,8 +21,7 @@ namespace mwmp
void update();
void charGen(int stageFirst, int stageEnd);
bool charGenThread(); // return true if CGStage::current == CGStage::end
bool processCharGen(); // return true if CGStage::current == CGStage::end
bool hasFinishedCharGen();
void updateStatsDynamic(bool forceUpdate = false);

@ -212,8 +212,7 @@ void Main::frame(float dt)
void Main::updateWorld(float dt) const
{
if (!mLocalPlayer->charGenThread())
if (!mLocalPlayer->processCharGen())
return;
static bool init = true;

@ -154,9 +154,10 @@ namespace mwmp
{
public:
struct CGStage
struct CharGenState
{
int current, end;
int currentStage, endStage;
bool isFinished;
};
struct GUIMessageBox
@ -227,7 +228,7 @@ namespace mwmp
ESM::Class charClass;
std::string birthsign;
std::string chatMessage;
CGStage charGenStage;
CharGenState charGenState;
std::string passw;
bool isWerewolf;

@ -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);
}

Loading…
Cancel
Save