1+ /* *
2+ * =============================================================================
3+ * Source Python
4+ * Copyright (C) 2012-2018 Source Python Development Team. All rights reserved.
5+ * =============================================================================
6+ *
7+ * This program is free software; you can redistribute it and/or modify it under
8+ * the terms of the GNU General Public License, version 3.0, as published by the
9+ * Free Software Foundation.
10+ *
11+ * This program is distributed in the hope that it will be useful, but WITHOUT
12+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14+ * details.
15+ *
16+ * You should have received a copy of the GNU General Public License along with
17+ * this program. If not, see <http://www.gnu.org/licenses/>.
18+ *
19+ * As a special exception, the Source Python Team gives you permission
20+ * to link the code of this program (as well as its derivative works) to
21+ * "Half-Life 2," the "Source Engine," and any Game MODs that run on software
22+ * by the Valve Corporation. You must obey the GNU General Public License in
23+ * all respects for all other code used. Additionally, the Source.Python
24+ * Development Team grants this exception to all derivative works.
25+ */
26+
27+ // ============================================================================
28+ // >> INCLUDES
29+ // ============================================================================
30+ // Source.Python
31+ #include " entities.h"
32+
33+
34+ // ============================================================================
35+ // >> External variables
36+ // ============================================================================
37+ extern IMDLCache *modelcache;
38+
39+
40+ // ============================================================================
41+ // >> IServerUnknownExt
42+ // ============================================================================
43+ const char * IServerUnknownExt::GetClassname (IServerUnknown* pUnknown)
44+ {
45+ IServerNetworkable* pNetworkable = pUnknown->GetNetworkable ();
46+ if (!pNetworkable)
47+ BOOST_RAISE_EXCEPTION (PyExc_ValueError, " Failed to get the IServerNetworkable pointer." );
48+
49+ return pNetworkable->GetClassName ();
50+ }
51+
52+ bool IServerUnknownExt::IsNetworked (IServerUnknown* pUnknown)
53+ {
54+ IServerNetworkable *pServerNetworkable = pUnknown->GetNetworkable ();
55+ if (pServerNetworkable)
56+ return pServerNetworkable->GetEdict () != NULL ;
57+
58+ return false ;
59+ }
60+
61+
62+ // ============================================================================
63+ // >> ServerEntityExt
64+ // ============================================================================
65+ void ServerEntityExt::SetModelName (IServerEntity *pServerEntity, const char *szModelName)
66+ {
67+ CBaseEntity *pBaseEntity = pServerEntity->GetBaseEntity ();
68+ if (!pBaseEntity)
69+ BOOST_RAISE_EXCEPTION (PyExc_ValueError, " BaseEntity is NULL." );
70+
71+ ((CBaseEntityWrapper *)pBaseEntity)->SetKeyValue (" model" , szModelName);
72+ }
73+
74+ MDLHandle_t ServerEntityExt::get_model_handle (IServerEntity *pServerEntity)
75+ {
76+ string_t name = pServerEntity->GetModelName ();
77+ if (!name)
78+ return MDLHANDLE_INVALID ;
79+
80+ return modelcache->FindMDL (name.ToCStr ());
81+ }
82+
83+ studiohdr_t * ServerEntityExt::get_model_header (IServerEntity *pServerEntity)
84+ {
85+ MDLHandle_t handle = get_model_handle (pServerEntity);
86+ if (handle == MDLHANDLE_INVALID )
87+ return NULL ;
88+
89+ return modelcache->GetStudioHdr (handle);
90+ }
0 commit comments