Last active
April 28, 2018 11:53
-
-
Save nielsAD/e30d465a58efc3d599f04099d9149365 to your computer and use it in GitHub Desktop.
ent-ghost stageplayer race selection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/game_base.cpp b/game_base.cpp | |
index 738267e..99a2e11 100644 | |
--- a/game_base.cpp | |
+++ b/game_base.cpp | |
@@ -2846,7 +2846,7 @@ void CBaseGame :: AddPlayerFast( CStagePlayer *potential ) | |
Player->SetScore( potential->GetScore( ) ); | |
m_Players.push_back( Player ); | |
- m_Slots[SID] = CGameSlot( Player->GetPID( ), 100, SLOTSTATUS_OCCUPIED, 0, m_Slots[SID].GetTeam( ), m_Slots[SID].GetColour( ), m_Slots[SID].GetRace( ) ); | |
+ m_Slots[SID] = CGameSlot( Player->GetPID( ), 100, SLOTSTATUS_OCCUPIED, 0, m_Slots[SID].GetTeam( ), m_Slots[SID].GetColour( ), potential->GetRace( ) ); | |
// send virtual host info and fake player info (if present) to the new player | |
diff --git a/stageplayer.cpp b/stageplayer.cpp | |
index 034f4b4..dd3bf14 100644 | |
--- a/stageplayer.cpp | |
+++ b/stageplayer.cpp | |
@@ -102,10 +102,8 @@ bool CStagePlayer :: Update( void *fd ) | |
else if( m_LoadingStage == 1 ) | |
{ | |
- vector<CGameSlot> Slots = m_GHost->m_Map->GetSlots( ); | |
- Slots[0] = CGameSlot( m_PID, 100, SLOTSTATUS_OCCUPIED, 0, Slots[0].GetTeam( ), Slots[0].GetColour( ), Slots[0].GetRace( ) ); | |
- Send( m_Protocol->SEND_W3GS_SLOTINFOJOIN( m_PID, m_Socket->GetPort( ), GetExternalIP( ), Slots, 100, m_GHost->m_Map->GetMapLayoutStyle( ), m_GHost->m_Map->GetMapNumPlayers( ) ) ); | |
- | |
+ UpdateSlots( true ); | |
+ | |
// add virtual player | |
m_VirtualPID = 1; | |
m_ChatPID = 2; | |
@@ -469,6 +467,13 @@ void CStagePlayer :: ProcessPackets( ) | |
m_GHost->BroadcastChat( m_Name + "@" + Realm, Message ); | |
} | |
} | |
+ } else if( ChatPlayer->GetType( ) == CIncomingChatPlayer :: CTH_RACECHANGE && m_Race & SLOTRACE_SELECTABLE ) { | |
+ unsigned char race = ChatPlayer->GetByte( ); | |
+ if( m_Race & race == 0 && ( race == SLOTRACE_HUMAN || race == SLOTRACE_ORC || race == SLOTRACE_NIGHTELF || race == SLOTRACE_UNDEAD || race == SLOTRACE_RANDOM ) ) | |
+ { | |
+ m_Race = race | SLOTRACE_SELECTABLE; | |
+ UpdateSlots( false ); | |
+ } | |
} | |
} | |
@@ -501,6 +506,22 @@ void CStagePlayer :: SendChat( string message, bool local ) | |
Send( m_Protocol->SEND_W3GS_CHAT_FROM_HOST( m_ChatPID, UTIL_CreateByteArray( m_PID ), 16, BYTEARRAY( ), message ) ); | |
} | |
+void CStagePlayer :: UpdateSlots( bool join ) { | |
+ vector<CGameSlot> Slots = m_GHost->m_Map->GetSlots( ); | |
+ | |
+ if ( join ) { | |
+ m_Race = Slots[0].GetRace( ); | |
+ } | |
+ | |
+ Slots[0] = CGameSlot( m_PID, 100, SLOTSTATUS_OCCUPIED, 0, Slots[0].GetTeam( ), Slots[0].GetColour( ), m_Race ); | |
+ | |
+ if ( join ) { | |
+ Send( m_Protocol->SEND_W3GS_SLOTINFOJOIN( m_PID, m_Socket->GetPort( ), GetExternalIP( ), Slots, 100, m_GHost->m_Map->GetMapLayoutStyle( ), m_GHost->m_Map->GetMapNumPlayers( ) ) ); | |
+ } else { | |
+ Send( m_Protocol->SEND_W3GS_SLOTINFO( Slots, 100, m_GHost->m_Map->GetMapLayoutStyle( ), m_GHost->m_Map->GetMapNumPlayers( ) ) ); | |
+ } | |
+} | |
+ | |
bool CStagePlayer :: IsScoreAcceptable( double nScore, int nScoreType ) | |
{ | |
if( nScore > m_Score - m_ScoreRange && nScore < m_Score + m_ScoreRange ) | |
diff --git a/stageplayer.h b/stageplayer.h | |
index 3cbf755..da92952 100644 | |
--- a/stageplayer.h | |
+++ b/stageplayer.h | |
@@ -58,6 +58,7 @@ protected: | |
uint32_t m_PID; // PID randomly assigned to this player | |
uint32_t m_VirtualPID; // PID for virtual player (so that we receive chat messages) | |
uint32_t m_ChatPID; // PID for broadcast messages | |
+ unsigned char m_Race; // race (1 = human, 2 = orc, 4 = night elf, 8 = undead, 32 = random) | |
double m_Score; | |
double m_ScoreRange; // allowed deviation from our score of players that we're willing to play with | |
@@ -85,6 +86,7 @@ public: | |
string GetName( ) { return m_Name; } | |
string GetRealm( ) { return m_Realm; } | |
uint32_t GetPID( ) { return m_PID; } | |
+ unsigned char GetRace( ) { return m_Race; } | |
bool GetReady( ) { return m_LoadingStage == 4; } | |
double GetScore( ) { return m_Score; } | |
@@ -101,6 +103,7 @@ public: | |
void Send( BYTEARRAY data ); | |
void SendChat( string message, bool local = true ); | |
+ void UpdateSlots( bool join ); | |
bool IsScoreAcceptable( double nScore, int nScoreType ); | |
void RemoveVirtual( ); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment