Skip to content

Commit 18389d6

Browse files
committed
Initial gamerules commit
1 parent a832762 commit 18389d6

File tree

4 files changed

+196
-0
lines changed

4 files changed

+196
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
engines.gamerules module
2+
=========================
3+
4+
.. automodule:: engines.gamerules
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# ../engines/gamerules.py
2+
3+
"""Provides access to the gamerules instance."""
4+
5+
# =============================================================================
6+
# >> IMPORTS
7+
# =============================================================================
8+
# Source.Python Imports
9+
# Memory
10+
from memory import make_object
11+
# Entities
12+
from entities.entity import BaseEntity
13+
from entities.factories import factory_dictionary
14+
15+
16+
# =============================================================================
17+
# >> FORWARD IMPORTS
18+
# =============================================================================
19+
# Source.Python Imports
20+
# Engines
21+
from _engines._gamerules import GameSystem
22+
from _engines._gamerules import GameSystemPerFrame
23+
from _engines._gamerules import BaseGameSystemPerFrame
24+
from _engines._gamerules import AutoGameSystemPerFrame
25+
from _engines._gamerules import GameRules
26+
27+
28+
# =============================================================================
29+
# >> ALL DECLARATION
30+
# =============================================================================
31+
__all__ = (
32+
'AutoGameSystemPerFrame',
33+
'BaseGameSystemPerFrame',
34+
'GameSystem',
35+
'GameSystemPerFrame',
36+
'find_gamerules',
37+
'find_gamerules_proxy_name')
38+
39+
40+
# =============================================================================
41+
# >> FUNCTIONS
42+
# =============================================================================
43+
def find_gamerules_proxy_name():
44+
"""Tries to find the gamerules proxy name (e. g. ``cs_gamerules``).
45+
46+
:raise ValueError:
47+
Raised if the gamerules proxy name wasn't found.
48+
:rtype: str
49+
"""
50+
for classname in factory_dictionary:
51+
if 'gamerules' not in classname:
52+
continue
53+
54+
return classname
55+
56+
raise ValueError('Unable to find gamerules proxy name.')
57+
58+
def find_gamerules():
59+
"""Tries to find the gamerules instance.
60+
61+
:raise ValueError:
62+
Raised if the gamerules instance wasn't found.
63+
:rtype: GameRules
64+
"""
65+
proxy = BaseEntity.find_or_create(find_gamerules_proxy_name())
66+
cls = proxy.server_class
67+
while cls:
68+
for prop in cls.table:
69+
if 'gamerules_data' not in prop.name:
70+
continue
71+
72+
return make_object(
73+
GameRules,
74+
prop.data_table_proxy_function(None, None, None, None, 0))
75+
76+
cls = cls.next
77+
78+
raise ValueError('Unable to find gamerules.')

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ Set(SOURCEPYTHON_ENGINES_MODULE_SOURCES
193193
core/modules/engines/engines_server_wrap.cpp
194194
core/modules/engines/engines_sound_wrap.cpp
195195
core/modules/engines/engines_trace_wrap.cpp
196+
core/modules/engines/engines_gamerules_wrap.cpp
196197
)
197198

198199
# ------------------------------------------------------------------
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/**
2+
* =============================================================================
3+
* Source Python
4+
* Copyright (C) 2012-2015 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 "export_main.h"
32+
#include "sp_main.h"
33+
34+
// SDK
35+
#include "game/shared/gamerules.h"
36+
37+
38+
//---------------------------------------------------------------------------------
39+
// Forward declarations.
40+
//---------------------------------------------------------------------------------
41+
void export_gamerules(scope);
42+
43+
44+
//---------------------------------------------------------------------------------
45+
// Declare the _sound module.
46+
//---------------------------------------------------------------------------------
47+
DECLARE_SP_SUBMODULE(_engines, _gamerules)
48+
{
49+
export_gamerules(_gamerules);
50+
}
51+
52+
53+
//-----------------------------------------------------------------------------
54+
// Expose gamerules.
55+
//-----------------------------------------------------------------------------
56+
void export_gamerules(scope _gamerules)
57+
{
58+
// IGameSystem
59+
class_<IGameSystem, boost::noncopyable> GameSystem("GameSystem", no_init);
60+
61+
GameSystem.add_property(
62+
"name",
63+
&IGameSystem::Name);
64+
65+
GameSystem ADD_MEM_TOOLS(IGameSystem);
66+
67+
68+
// IGameSystemPerFrame
69+
class_<IGameSystemPerFrame, bases<IGameSystem>, boost::noncopyable> GameSystemPerFrame("GameSystemPerFrame", no_init);
70+
71+
GameSystemPerFrame ADD_MEM_TOOLS(IGameSystemPerFrame);
72+
73+
74+
// CBaseGameSystemPerFrame
75+
class_<CBaseGameSystemPerFrame, bases<IGameSystemPerFrame>, boost::noncopyable> BaseGameSystemPerFrame("BaseGameSystemPerFrame", no_init);
76+
77+
BaseGameSystemPerFrame ADD_MEM_TOOLS(CBaseGameSystemPerFrame);
78+
79+
80+
// CAutoGameSystemPerFrame
81+
class_<CAutoGameSystemPerFrame, bases<CBaseGameSystemPerFrame>, boost::noncopyable> AutoGameSystemPerFrame("AutoGameSystemPerFrame", no_init);
82+
83+
AutoGameSystemPerFrame.add_property(
84+
"next",
85+
make_getter(&CAutoGameSystemPerFrame::m_pNext, reference_existing_object_policy()));
86+
87+
AutoGameSystemPerFrame ADD_MEM_TOOLS(CAutoGameSystemPerFrame);
88+
89+
90+
// CGameRules
91+
class_<CGameRules, bases<CAutoGameSystemPerFrame>, boost::noncopyable> GameRules("GameRules", no_init);
92+
93+
GameRules.add_property(
94+
"game_description",
95+
&CGameRules::GetGameDescription);
96+
97+
GameRules.def(
98+
"should_collide",
99+
&CGameRules::ShouldCollide);
100+
101+
GameRules.def(
102+
"get_tagged_convar_list",
103+
&CGameRules::GetTaggedConVarList);
104+
105+
GameRules ADD_MEM_TOOLS(CGameRules);
106+
107+
BEGIN_CLASS_INFO(CGameRules)
108+
FUNCTION_INFO(DeathNotice)
109+
END_CLASS_INFO()
110+
}

0 commit comments

Comments
 (0)