From a837174564a030bf76adf5ab8beae2ad59a61ee4 Mon Sep 17 00:00:00 2001 From: mittorn Date: Sun, 22 Jan 2017 09:00:56 +0000 Subject: [PATCH] Move coop stuff to coop.cpp --- dlls/client.cpp | 16 +++----- dlls/coop.cpp | 63 ++++++++++++++++++++++++++++++- dlls/coop_util.h | 16 +++++++- dlls/multiplay_gamerules.cpp | 73 ------------------------------------ 4 files changed, 81 insertions(+), 87 deletions(-) diff --git a/dlls/client.cpp b/dlls/client.cpp index b9ade580..abee299e 100644 --- a/dlls/client.cpp +++ b/dlls/client.cpp @@ -664,10 +664,6 @@ void ServerDeactivate( void ) // } -void CoopClearData( void ); -void CoopApplyData( void ); -void CoopClearWeaponList( void ); - void ServerActivate( edict_t *pEdictList, int edictCount, int clientMax ) { int i; @@ -704,7 +700,7 @@ void ServerActivate( edict_t *pEdictList, int edictCount, int clientMax ) LinkUserMessages(); if( mp_coop.value ) { - CoopApplyData(); + UTIL_CoopApplyData(); for( int i = 1; i <= gpGlobals->maxClients; i++ ) { CBasePlayer *plr = (CBasePlayer*)UTIL_PlayerByIndex( i ); @@ -769,13 +765,12 @@ void ParmsNewLevel( void ) if ( pSaveData ) { pSaveData->connectionCount = BuildChangeList( pSaveData->levelList, MAX_LEVEL_CONNECTIONS ); - //CoopApplyData(); } else if( mp_coop_changelevel.value ) { - CoopClearData(); - CoopClearWeaponList(); + UTIL_CoopClearData(); + g_WeaponList.Clear(); } } @@ -789,13 +784,12 @@ void ParmsChangeLevel( void ) if ( pSaveData ) { pSaveData->connectionCount = BuildChangeList( pSaveData->levelList, MAX_LEVEL_CONNECTIONS ); - //CoopApplyData(); } else if( mp_coop_changelevel.value ) { - CoopClearData(); - CoopClearWeaponList(); + UTIL_CoopClearData(); + g_WeaponList.Clear(); } } diff --git a/dlls/coop.cpp b/dlls/coop.cpp index e532579e..ae71acba 100644 --- a/dlls/coop.cpp +++ b/dlls/coop.cpp @@ -173,7 +173,7 @@ struct checkpoint_s } g_checkpoints[4]; -void CoopClearData( void ) +void UTIL_CoopClearData( void ) { // nullify SavedCoords l_SavedCoords = {0}; @@ -182,7 +182,7 @@ void CoopClearData( void ) } bool g_fPause; -void CoopApplyData( void ) +void UTIL_CoopApplyData( void ) { if( s_SavedCoords.valid ) { @@ -627,3 +627,62 @@ CBaseEntity *UTIL_CoopGetPlayerTrain( CBaseEntity *pPlayer) return NULL; return train; } + + + +// Collect all weapons tat player touchet in coop ant give to all players at spawn + +CWeaponList g_WeaponList; + +void CWeaponList::Clear() +{ + m_iWeapons = 0; +} +void CWeaponList::GiveToPlayer(CBasePlayer *pPlayer) +{ + for(int i = 0; i < m_iWeapons;i++) + pPlayer->GiveNamedItem(weapons[i]); +} +void CWeaponList::AddWeapon( const char *classname ) +{ + int i; + for(i = 0; i < m_iWeapons;i++) + if(!strcmp(weapons[i], classname)) + return; + strcpy(weapons[m_iWeapons++], classname); +} +extern int gmsgShowMenu; + +void UTIL_CoopShowMenu( CBasePlayer *pPlayer, const char *title, int count, const char **slot, signed char time ) +{ + if( pPlayer->m_fTouchMenu) + { + char buf[256]; + #define MENU_STR(VAR) (#VAR) + sprintf( buf, MENU_STR(slot10\ntouch_hide _coops*\ntouch_show _coops\ntouch_addbutton "_coopst" "#%s" "" 0.16 0.11 0.41 0.3 0 255 0 255 78 1.5\n), title); + CLIENT_COMMAND( pPlayer->edict(), buf); + for( int i = 0; i < count; i++ ) + { + sprintf( buf, MENU_STR(touch_settexture _coops%d "#%d. %s"\ntouch_show _coops%d\n), i+1, i+1, slot[i], i + 1 ); + CLIENT_COMMAND( pPlayer->edict(), buf); + } + } + else + { + char buf[128], *pbuf = buf; + short int flags = 1<<9; + pbuf += sprintf( pbuf, "^2%s:\n", title ); + for( int i = 0; i < count; i++ ) + { + pbuf += sprintf( pbuf, "^3%d.^7 %s\n", i+1, slot[i]); + flags |= 1<pev); + WRITE_SHORT( flags ); // slots + WRITE_CHAR( time ); // show time + WRITE_BYTE( 0 ); // need more + WRITE_STRING( buf ); + MESSAGE_END(); + } + //CLIENT_COMMAND( pPlayer->edict(), "exec touch_default/numbers.cfg\n"); +} diff --git a/dlls/coop_util.h b/dlls/coop_util.h index 74b02e51..7edf5bf7 100644 --- a/dlls/coop_util.h +++ b/dlls/coop_util.h @@ -65,7 +65,8 @@ bool UTIL_CoopRestorePlayerCoords(CBaseEntity *player, Vector *origin, Vector *a void UTIL_CoopSaveTrain( CBaseEntity *pPlayer, SavedCoords *coords); Vector UTIL_FixupSpawnPoint(Vector spawn); void UTIL_CoopActivateChangeLevel( CBaseEntity *pTrigger ); - +void UTIL_CoopClearData( void ); +void UTIL_CoopApplyData( void ); #ifdef PLAYER_H void UTIL_CoopKickPlayer(CBaseEntity *pPlayer); bool UTIL_CoopIsBadPlayer( CBaseEntity *plr ); @@ -101,6 +102,19 @@ public: }; extern GlobalMenu g_GlobalMenu; + +class CWeaponList +{ + char weapons[64][256]; + int m_iWeapons; +public: + void AddWeapon( const char *classname ); + void GiveToPlayer(CBasePlayer *pPlayer); + void Clear(); +}; + +extern CWeaponList g_WeaponList; + #endif extern struct SavedCoords g_SavedCoords, s_SavedCoords; diff --git a/dlls/multiplay_gamerules.cpp b/dlls/multiplay_gamerules.cpp index c2f6daab..3f7dbbee 100644 --- a/dlls/multiplay_gamerules.cpp +++ b/dlls/multiplay_gamerules.cpp @@ -65,79 +65,6 @@ public: static CMultiplayGameMgrHelper g_GameMgrHelper; #endif -// Collect all weapons tat player touchet in coop ant give to all players at spawn -class CWeaponList -{ - char weapons[64][256]; - int m_iWeapons; -public: - void AddWeapon( const char *classname ) - { - int i; - for(i = 0; i < m_iWeapons;i++) - if(!strcmp(weapons[i], classname)) - return; - strcpy(weapons[m_iWeapons++], classname); - } - void GiveToPlayer(CBasePlayer *player) - { - for(int i = 0; i < m_iWeapons;i++) - player->GiveNamedItem(weapons[i]); - } - void Clear() - { - m_iWeapons = 0; - } -} g_WeaponList; - -void CoopClearWeaponList( void ) -{ - g_WeaponList.Clear(); -} -extern int g_iMenu; - - - -extern int gmsgShowMenu; - -void UTIL_CoopShowMenu( CBasePlayer *pPlayer, const char *title, int count, const char **slot, signed char time ) -{ - if( pPlayer->m_fTouchMenu) - { - char buf[256]; - #define MENU_STR(VAR) (#VAR) - sprintf( buf, MENU_STR(slot10\ntouch_hide _coops*\ntouch_show _coops\ntouch_addbutton "_coopst" "#%s" "" 0.16 0.11 0.41 0.3 0 255 0 255 78 1.5\n), title); - CLIENT_COMMAND( pPlayer->edict(), buf); - for( int i = 0; i < count; i++ ) - { - sprintf( buf, MENU_STR(touch_settexture _coops%d "#%d. %s"\ntouch_show _coops%d\n), i+1, i+1, slot[i], i + 1 ); - CLIENT_COMMAND( pPlayer->edict(), buf); - } - } - else - { - char buf[128], *pbuf = buf; - short int flags = 1<<9; - pbuf += sprintf( pbuf, "^2%s:\n", title ); - for( int i = 0; i < count; i++ ) - { - pbuf += sprintf( pbuf, "^3%d.^7 %s\n", i+1, slot[i]); - flags |= 1<pev); - WRITE_SHORT( flags ); // slots - WRITE_CHAR( time ); // show time - WRITE_BYTE( 0 ); // need more - WRITE_STRING( buf ); - MESSAGE_END(); - } - //CLIENT_COMMAND( pPlayer->edict(), "exec touch_default/numbers.cfg\n"); -} - -void UTIL_CoopMenu( CBasePlayer *pPlayer ); - -void UTIL_CoopVoteMenu( CBasePlayer *pPlayer ); - //********************************************************* // Rules for the half-life multiplayer game.