Skip to content

Add access to CGameRules and its properties #363

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Dec 21, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add back game rules
  • Loading branch information
Ayuto committed Nov 15, 2020
commit 76e3b5ae3021cc1365f300b0952d7adbb5fbdb4f
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
engines.gamerules module
=========================

.. automodule:: engines.gamerules
:members:
:undoc-members:
:show-inheritance:
79 changes: 79 additions & 0 deletions addons/source-python/packages/source-python/engines/gamerules.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# ../engines/gamerules.py

"""Provides access to the gamerules instance."""

# =============================================================================
# >> IMPORTS
# =============================================================================
# Source.Python Imports
# Memory
from memory import make_object
# Entities
from entities.entity import BaseEntity
from entities.factories import factory_dictionary


# =============================================================================
# >> FORWARD IMPORTS
# =============================================================================
# Source.Python Imports
# Engines
from _engines._gamerules import GameSystem
from _engines._gamerules import GameSystemPerFrame
from _engines._gamerules import BaseGameSystemPerFrame
from _engines._gamerules import AutoGameSystemPerFrame
from _engines._gamerules import GameRules


# =============================================================================
# >> ALL DECLARATION
# =============================================================================
__all__ = (
'AutoGameSystemPerFrame',
'BaseGameSystemPerFrame',
'GameSystem',
'GameSystemPerFrame',
'find_game_rules',
'find_game_rules_proxy_name',)


# =============================================================================
# >> FUNCTIONS
# =============================================================================
def find_game_rules_proxy_name():
"""Find the entity name that proxies the game rules (e. g.
``cs_gamerules``).

:raise ValueError:
Raised if the game rules proxy name wasn't found.
:rtype: str
"""
for classname in factory_dictionary:
if 'gamerules' not in classname:
continue

return classname

raise ValueError('Unable to find game rules proxy name.')

def find_game_rules():
"""Find the game rules instance.

:raise ValueError:
Raised if the game rules instance wasn't found.
:rtype: GameRules
"""
proxy = BaseEntity.find_or_create(find_game_rules_proxy_name())
cls = proxy.server_class
while cls:
for prop in cls.table:
if 'gamerules_data' not in prop.name:
continue

return make_object(
GameRules,
prop.data_table_proxy_function(None, None, None, None, 0))

cls = cls.next

raise ValueError('Unable to find game rules.')
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ Set(SOURCEPYTHON_ENGINES_MODULE_SOURCES
core/modules/engines/engines_server_wrap.cpp
core/modules/engines/engines_sound_wrap.cpp
core/modules/engines/engines_trace_wrap.cpp
core/modules/engines/engines_gamerules_wrap.cpp
)

# ------------------------------------------------------------------
Expand Down
137 changes: 137 additions & 0 deletions src/core/modules/engines/engines_gamerules_wrap.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/**
* =============================================================================
* Source Python
* Copyright (C) 2012-2015 Source Python Development Team. All rights reserved.
* =============================================================================
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*
* As a special exception, the Source Python Team gives you permission
* to link the code of this program (as well as its derivative works) to
* "Half-Life 2," the "Source Engine," and any Game MODs that run on software
* by the Valve Corporation. You must obey the GNU General Public License in
* all respects for all other code used. Additionally, the Source.Python
* Development Team grants this exception to all derivative works.
*/

//---------------------------------------------------------------------------------
// Includes.
//---------------------------------------------------------------------------------
// Source.Python
#include "export_main.h"
#include "sp_main.h"

// SDK
#include "game/shared/gamerules.h"


//---------------------------------------------------------------------------------
// Forward declarations.
//---------------------------------------------------------------------------------
void export_game_system(scope);
void export_game_system_per_frame(scope);
void export_base_game_system_per_frame(scope);
void export_auto_game_system_per_frame(scope);
void export_game_rules(scope);


//---------------------------------------------------------------------------------
// Declare the _sound module.
//---------------------------------------------------------------------------------
DECLARE_SP_SUBMODULE(_engines, _gamerules)
{
export_game_system(_gamerules);
export_game_system_per_frame(_gamerules);
export_base_game_system_per_frame(_gamerules);
export_auto_game_system_per_frame(_gamerules);
export_game_rules(_gamerules);
}


//-----------------------------------------------------------------------------
// Expose GameSystem.
//-----------------------------------------------------------------------------
void export_game_system(scope _gamerules)
{
class_<IGameSystem, boost::noncopyable> GameSystem("GameSystem", no_init);

GameSystem.add_property(
"name",
&IGameSystem::Name);

GameSystem ADD_MEM_TOOLS(IGameSystem);
}


//-----------------------------------------------------------------------------
// Expose GameSystemPerFrame.
//-----------------------------------------------------------------------------
void export_game_system_per_frame(scope _gamerules)
{
class_<IGameSystemPerFrame, bases<IGameSystem>, boost::noncopyable> GameSystemPerFrame("GameSystemPerFrame", no_init);

GameSystemPerFrame ADD_MEM_TOOLS(IGameSystemPerFrame);
}


//-----------------------------------------------------------------------------
// Expose BaseGameSystemPerFrame.
//-----------------------------------------------------------------------------
void export_base_game_system_per_frame(scope _gamerules)
{
class_<CBaseGameSystemPerFrame, bases<IGameSystemPerFrame>, boost::noncopyable> BaseGameSystemPerFrame("BaseGameSystemPerFrame", no_init);

BaseGameSystemPerFrame ADD_MEM_TOOLS(CBaseGameSystemPerFrame);
}


//-----------------------------------------------------------------------------
// Expose AutoGameSystemPerFrame.
//-----------------------------------------------------------------------------
void export_auto_game_system_per_frame(scope _gamerules)
{
class_<CAutoGameSystemPerFrame, bases<CBaseGameSystemPerFrame>, boost::noncopyable> AutoGameSystemPerFrame("AutoGameSystemPerFrame", no_init);

AutoGameSystemPerFrame.add_property(
"next",
make_getter(&CAutoGameSystemPerFrame::m_pNext, reference_existing_object_policy()));

AutoGameSystemPerFrame ADD_MEM_TOOLS(CAutoGameSystemPerFrame);
}


//-----------------------------------------------------------------------------
// Expose GameRules.
//-----------------------------------------------------------------------------
void export_game_rules(scope _gamerules)
{
class_<CGameRules, bases<CAutoGameSystemPerFrame>, boost::noncopyable> GameRules("GameRules", no_init);

GameRules.add_property(
"game_description",
&CGameRules::GetGameDescription);

GameRules.def(
"should_collide",
&CGameRules::ShouldCollide);

GameRules.def(
"get_tagged_convar_list",
&CGameRules::GetTaggedConVarList);

GameRules ADD_MEM_TOOLS(CGameRules);

BEGIN_CLASS_INFO(CGameRules)
FUNCTION_INFO(DeathNotice)
END_CLASS_INFO()
}