Nuclide
Software Development Kit for id Technology (BETA)
Loading...
Searching...
No Matches
ncRuleDelegate Class Reference

About this class

This class represents active gamerules.

The ncRuleDelegate class is for any set of active gamerules. It can be accessed in QuakeC via the global g_grMode from the server-side.

Choosing A Ruleset

Upon server init, the game will query the weak function Game_DefaultRules(), which can be re-implemented with the same name by the game developer in their server game. The return value should either be __NULL__ or the name of a progs within <gamedir>/progs/.

By default, the game will load either <gamedir>/progs/singleplayer.dat when it's only a singleplayer client or the console variable for coop is 1, or <gamedir>/progs/deathmatch.dat in any other case. If you happen to set the server-side console variable g_gametype to a custom string, it will attempt to load a named progs that can be found under <gamedir>/progs/.

Here's the current implementation of said function:

__weak string
Game_DefaultRules(void)
{
string gameType = cvars.GetString("g_gametype");
if (!STRING_SET(gameType)) {
bool isCoop = cvars.GetBool("coop");
bool isSingle = (cvars.GetInteger("sv_playerslots") <= 1) ? (true) : (false);
gameType = (isSingle || isCoop) == (true) ? "singleplayer" : "deathmatch";
}
return (gameType);
}
cvarAPI_t cvars
Access cvarAPI_t functions using this variable.
Definition api.h:122

If you only plan on having one mode, ever, and disallow custom game modes - you can define it like this anywhere:

string
Game_DefaultRules(void)
{
return ("deathmatch");
}

The progs in question is then able to override any methods of the ncGameRule class.

Implementing RuleC Progs

When we decide to load a rule from an external progs, that progs can be implemented with as many binds as you like. The only requirement is you include the header found under src/server/api.h.

Example RuleC

Here's a simple deathmatch rule, which will increment the score on the score-board for every player frag:

#pragma PROGS_DAT "../../progs/deathmatch.dat"
#include "../../../src/server/api.h"
void
CodeCallback_Precaches(void)
{
precache.Entity("player"); // Precache everything associated with the player decl
}
void
CodeCallback_StartGameType(void)
{
motd.LoadDefault(); // Multiplayer game, so load the message of the day
}
void
CodeCallback_PlayerSpawn(entity playerTarget)
{
ents.ChangeToClass(playerTarget, "player"); // Turn the client into a fresh player
game.TeleportToSpawn(playerTarget); // Teleport the player to its destined start position
}
bool
CodeCallback_PlayerRequestRespawn(entity playerTarget)
{
CodeCallback_PlayerSpawn(playerTarget); // When we request a respawn, let it happen
return (true);
}
void
CodeCallback_PlayerKilled(entity playerTarget, entity inflictor, entity attacker, string weapon)
{
playerTarget.deaths++; // increment death counter
if (is.Player(attacker)) {
if (playerTarget == attacker) {
attacker.frags--; // scoreboard penalty for the flub
} else {
attacker.frags++; // scoreboard reward
}
}
}
var weaponAPI_t weapon
Access weaponAPI_t functions using this variable.
Definition api_func.h:515
var motdAPI_t motd
Access motdAPI_t functions using this variable.
Definition api_func.h:136
var gameAPI_t game
Access gameAPI_t functions using this variable.
Definition api_func.h:124
var entsAPI_t ents
Access entsAPI_t functions using this variable.
Definition api_func.h:92
precacheAPI_t precache
Access precacheAPI_t functions using this variable.
Definition api.h:506
isAPI_t is
Access nextAPI_t functions using this variable.
Definition api.h:554
float ChangeToClass(entity targetEntity, string className)
Transitions an entity from one class to another.
void TeleportToSpawn(entity teleportingEntity)
Teleports an entity to their ideal spawn-point.
float Player(entity entityToCheck)
Returns true/false depending on if the entity is a player.

Class To Progs Callback Mappings

Left = class method, right = name of the callback function for you to implement in progs.

ncRuleDelegate::Title = CodeCallback_Title
ncRuleDelegate::ClientCommand = CodeCallback_ClientCommand
ncRuleDelegate::ConsoleCommand = CodeCallback_ConsoleCommand
ncRuleDelegate::FrameStart = CodeCallback_FrameStart
ncRuleDelegate::ImpulseCommand = CodeCallback_ImpulseCommand
ncRuleDelegate::InitPostEnts = CodeCallback_StartGameType
ncRuleDelegate::Input = CodeCallback_Input
ncRuleDelegate::NPCDeath = CodeCallback_NPCKilled
ncRuleDelegate::PlayerCanAttack = CodeCallback_PlayerCanAttack
ncRuleDelegate::PlayerConnect = CodeCallback_PlayerConnect
ncRuleDelegate::PlayerDeath = CodeCallback_PlayerKilled
ncRuleDelegate::PlayerDisconnect = CodeCallback_PlayerDisconnect
ncRuleDelegate::PlayerPain = CodeCallback_PlayerDamage
ncRuleDelegate::PlayerPreFrame = CodeCallback_PlayerPreFrame
ncRuleDelegate::PlayerRequestRespawn = CodeCallback_PlayerRequestRespawn
ncRuleDelegate::PlayerRequestTeam = CodeCallback_CallRequestTeam
ncRuleDelegate::PlayerSpawn = CodeCallback_PlayerSpawn

The underlying return values and parameters are inherited from its class counter-part.

Inheritance diagram for ncRuleDelegate:
ncIO

Public Member Functions

void ncRuleDelegate (void)
 
virtual void Save (float)
 Handles saving a copy of this entity to a given filehandle.
 
virtual void Restore (string, string)
 Similar to ncIO::SpawnKey() but for save-game fields.
 
virtual void RestoreComplete (void)
 Called when the entity has been successfully restored from a savegame file.
 
virtual void Input (entity, string, string)
 Called when we are being prompted by another object/function with an input message.
 
virtual void InitPostEnts (void)
 Overridable: Called when all map entities have initialized.
 
virtual void Precache (void)
 Overridable: Called from initents().
 
virtual void FrameStart (void)
 Overridable: Called every server frame.
 
virtual bool ConsoleCommand (ncPlayer, string)
 Overridable: Called when the server issues a console command.
 
virtual bool ClientCommand (ncClient, string)
 Overridable: Called when a client issues a client command.
 
virtual bool ImpulseCommand (ncClient, float)
 Overridable: Called when a client issues an impulse command.
 
virtual void PlayerConnect (ncPlayer)
 Overridable: Called when a ncPlayer joins the server.
 
virtual void PlayerDisconnect (ncPlayer)
 Overridable: Called when a ncPlayer leaves the server.
 
virtual void PlayerKill (ncPlayer)
 Overridable: Called when a ncPlayer issues the kill console command.
 
virtual void PlayerSpawn (ncPlayer)
 Overridable: Called when a ncPlayer spawns, called sometime after joining.
 
virtual void PlayerPreFrame (ncPlayer)
 Overridable: Called before running physics on the ncPlayer in question.
 
virtual void PlayerPostFrame (ncPlayer)
 Overridable: Called after running physics on the ncPlayer in question.
 
virtual void PlayerDeath (ncPlayer, ncEntity, ncEntity, string)
 Overridable: Called when a ncPlayer dies in the game.
 
virtual void PlayerPain (ncPlayer, ncActor, ncDict)
 Overridable: Called when a ncPlayer feels pain.
 
virtual bool PlayerCanAttack (ncPlayer)
 Overridable: Called to check if a ncPlayer can attack.
 
virtual void NPCDeath (ncActor, ncEntity, ncEntity)
 Overridable:: Called when an NPC gets killed.
 
virtual bool PlayerRequestRespawn (ncPlayer)
 Overridable: called when a ncPlayer requests a respawn.
 
virtual bool PlayerRequestTeam (ncPlayer, int team)
 Overridable: called when a ncPlayer requests joining a specific team.
 
virtual void LevelNewParms (void)
 Overridable: Called to set up new level parms for any ncPlayer.
 
virtual void LevelChangeParms (ncPlayer)
 Overridable: Called to store parms for a specific ncPlayer.
 
virtual int MaxItemPerSlot (int)
 Overridable: Returns how many items players can carry in a given slot.
 
virtual bool MonstersSpawn (void)
 Overridable: Returns if ncMonster or ncTalkMonster entities can spawn.
 
virtual void IntermissionStart (void)
 Called when intermission starts.
 
virtual void IntermissionCycle (void)
 Called when the intermission system calls a new map.
 
virtual void IntermissionEnd (void)
 Called when intermission ends.
 
virtual void IntermissionToPlayer (ncPlayer)
 Run to send a specific player to an intermission.
 
virtual bool InIntermission (void)
 Returns if the gamerules find themselves in an intermission.
 
virtual bool IsTeamplay (void)
 Returns if this gamerule considers itself teamplay oriented.
 
virtual bool IsMultiplayer (void)
 Returns if the gamerule is a multiplayer game.
 
virtual void ChatMessageAll (ncClient, string)
 Called by Nuclide when the server has received a chat message that is to be distributed amongst all clients, regardless of team.
 
virtual void ChatMessageTeam (ncClient, string)
 Called by Nuclide when the server has received a chat message that is to be distributed amongst all clients of the same team.
 
virtual string Title (void)
 Returns the title of the gamemode running.
 
nonvirtual void LinkProgs (void)
 
nonvirtual ncRuleDelegate ActiveInstance (void)
 

Constructor & Destructor Documentation

◆ ncRuleDelegate()

void ncRuleDelegate::ncRuleDelegate ( void )

Member Function Documentation

◆ ActiveInstance()

ncRuleDelegate ncRuleDelegate::ActiveInstance ( void )

◆ ChatMessageAll()

void ncRuleDelegate::ChatMessageAll ( ncClient cl,
string strMessage )
virtual

Called by Nuclide when the server has received a chat message that is to be distributed amongst all clients, regardless of team.

◆ ChatMessageTeam()

void ncRuleDelegate::ChatMessageTeam ( ncClient cl,
string strMessage )
virtual

Called by Nuclide when the server has received a chat message that is to be distributed amongst all clients of the same team.

◆ ClientCommand()

bool ncRuleDelegate::ClientCommand ( ncClient pl,
string cmd )
virtual

Overridable: Called when a client issues a client command.

◆ ConsoleCommand()

bool ncRuleDelegate::ConsoleCommand ( ncPlayer pl,
string cmd )
virtual

Overridable: Called when the server issues a console command.

◆ FrameStart()

void ncRuleDelegate::FrameStart ( void )
virtual

Overridable: Called every server frame.

◆ ImpulseCommand()

bool ncRuleDelegate::ImpulseCommand ( ncClient pl,
float num )
virtual

Overridable: Called when a client issues an impulse command.

◆ InIntermission()

bool ncRuleDelegate::InIntermission ( void )
virtual

Returns if the gamerules find themselves in an intermission.

◆ InitPostEnts()

void ncRuleDelegate::InitPostEnts ( void )
virtual

Overridable: Called when all map entities have initialized.

◆ Input()

void ncRuleDelegate::Input ( entity eAct,
string strInput,
string strData )
virtual

Called when we are being prompted by another object/function with an input message.

Reimplemented from ncIO.

◆ IntermissionCycle()

void ncRuleDelegate::IntermissionCycle ( void )
virtual

Called when the intermission system calls a new map.

◆ IntermissionEnd()

void ncRuleDelegate::IntermissionEnd ( void )
virtual

Called when intermission ends.

◆ IntermissionStart()

void ncRuleDelegate::IntermissionStart ( void )
virtual

Called when intermission starts.

Will send all current players to the intermission screen.

◆ IntermissionToPlayer()

void ncRuleDelegate::IntermissionToPlayer ( ncPlayer targetPlayer)
virtual

Run to send a specific player to an intermission.

Like when joining late.

◆ IsMultiplayer()

bool ncRuleDelegate::IsMultiplayer ( void )
virtual

Returns if the gamerule is a multiplayer game.

◆ IsTeamplay()

bool ncRuleDelegate::IsTeamplay ( void )
virtual

Returns if this gamerule considers itself teamplay oriented.

◆ LevelChangeParms()

void ncRuleDelegate::LevelChangeParms ( ncPlayer pl)
virtual

Overridable: Called to store parms for a specific ncPlayer.

◆ LevelNewParms()

void ncRuleDelegate::LevelNewParms ( void )
virtual

Overridable: Called to set up new level parms for any ncPlayer.

◆ LinkProgs()

void ncRuleDelegate::LinkProgs ( void )

◆ MaxItemPerSlot()

int ncRuleDelegate::MaxItemPerSlot ( int slot)
virtual

Overridable: Returns how many items players can carry in a given slot.

◆ MonstersSpawn()

bool ncRuleDelegate::MonstersSpawn ( void )
virtual

Overridable: Returns if ncMonster or ncTalkMonster entities can spawn.

◆ NPCDeath()

void ncRuleDelegate::NPCDeath ( ncActor npc,
ncEntity attacker,
ncEntity inflictor )
virtual

Overridable:: Called when an NPC gets killed.

◆ PlayerCanAttack()

bool ncRuleDelegate::PlayerCanAttack ( ncPlayer bp)
virtual

Overridable: Called to check if a ncPlayer can attack.

◆ PlayerConnect()

void ncRuleDelegate::PlayerConnect ( ncPlayer pl)
virtual

Overridable: Called when a ncPlayer joins the server.

◆ PlayerDeath()

void ncRuleDelegate::PlayerDeath ( ncPlayer deadPlayer,
ncEntity inflictor,
ncEntity attacker,
string weaponDef )
virtual

Overridable: Called when a ncPlayer dies in the game.

◆ PlayerDisconnect()

void ncRuleDelegate::PlayerDisconnect ( ncPlayer pl)
virtual

Overridable: Called when a ncPlayer leaves the server.

◆ PlayerKill()

void ncRuleDelegate::PlayerKill ( ncPlayer pl)
virtual

Overridable: Called when a ncPlayer issues the kill console command.

◆ PlayerPain()

void ncRuleDelegate::PlayerPain ( ncPlayer pl,
ncActor attacker,
ncDict damageDecl )
virtual

Overridable: Called when a ncPlayer feels pain.

◆ PlayerPostFrame()

void ncRuleDelegate::PlayerPostFrame ( ncPlayer pl)
virtual

Overridable: Called after running physics on the ncPlayer in question.

◆ PlayerPreFrame()

void ncRuleDelegate::PlayerPreFrame ( ncPlayer pl)
virtual

Overridable: Called before running physics on the ncPlayer in question.

◆ PlayerRequestRespawn()

bool ncRuleDelegate::PlayerRequestRespawn ( ncPlayer pl)
virtual

Overridable: called when a ncPlayer requests a respawn.

In a multiplayer game, it'll put you back into the game as a player. In a singleplayer game, it might load the most recent save.

Returns
True/false depending on the respawn succeeded.

◆ PlayerRequestTeam()

bool ncRuleDelegate::PlayerRequestTeam ( ncPlayer pl,
int team )
virtual

Overridable: called when a ncPlayer requests joining a specific team.

Returns
True/false depending on the team change success.

◆ PlayerSpawn()

void ncRuleDelegate::PlayerSpawn ( ncPlayer pl)
virtual

Overridable: Called when a ncPlayer spawns, called sometime after joining.

◆ Precache()

void ncRuleDelegate::Precache ( void )
virtual

Overridable: Called from initents().

◆ Restore()

void ncRuleDelegate::Restore ( string keyName,
string setValue )
virtual

Similar to ncIO::SpawnKey() but for save-game fields.

Whatever you write into file handles within your ncIO::Save() method needs to be read back in here.

Reimplemented from ncIO.

◆ RestoreComplete()

void ncRuleDelegate::RestoreComplete ( void )
virtual

Called when the entity has been successfully restored from a savegame file.

Reimplemented from ncIO.

◆ Save()

void ncRuleDelegate::Save ( float handle)
virtual

Handles saving a copy of this entity to a given filehandle.

Within you want to use the ncIO::SaveFloat() etc. methods to write the internal member attributes to the specified file handle.

Reimplemented from ncIO.

◆ Title()

string ncRuleDelegate::Title ( void )
virtual

Returns the title of the gamemode running.


The documentation for this class was generated from the following files: