mirror of
				https://github.com/TES3MP/openmw-tes3mp.git
				synced 2025-10-31 20:26:48 +00:00 
			
		
		
		
	[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; | ||||
| } | ||||
| 
 | ||||
| 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); | ||||
|  |  | |||
|  | @ -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, | ||||
|  |  | |||
|  | @ -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<Script::CallbackIdentity("OnPlayerEndCharGen")>(player.getId()); | ||||
|         } | ||||
|     }; | ||||
|  |  | |||
|  | @ -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) | ||||
|  |  | |||
|  | @ -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); | ||||
|  |  | |||
|  | @ -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; | ||||
|  |  | |||
|  | @ -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; | ||||
|  |  | |||
|  | @ -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…
	
		Reference in a new issue