Server Help

ASSS Custom Projects - Swappable game interface

Smong - Sun Jun 10, 2007 8:20 am
Post subject: Swappable game interface
I've come up with an interface to allow an arenas's gametype to be changed on the fly. This doesn't change the map, just the game. Possible uses include mervbot elim style voting on the game type at the end of each round. Or periodic voting on special side games like what the zone Battlefield had for a short time.

The way it works is one "swappable game manager" (sgm) module (not shown) decides which game to play and starts that game. When the game ends the sgm then picks the next game (this could use a rotation or a vote for example). The StopGame function is so the sgm may end the game early, the game module should stop itself after 1 round and call the GameoverFunc callback.

Code: Show/Hide
/* this is a generic interface for swappable games. a swappable game is a game
* type module that can be loaded/unloaded while an arena is still running, so
* you can rotate through several game types without changing arena. */

#ifndef __SWAPPABLEGAME_H
#define __SWAPPABLEGAME_H

/** the callback function when a game has been won. tgt contains the winners
* or NULL if there were none. */
typedef void (*GameoverFunc)(Arena *arena, const Target *tgt);

/** the fg_ctf interface struct */
typedef struct Iswappablegame
{
   INTERFACE_HEAD_DECL

   void (*StartGame)(Arena *arena, GameoverFunc func);
   void (*StopGame)(Arena *arena);
} Iswappablegame;

#endif

I put a target in the GameoverFunc, it's up to the programmer whether the sgm awards points or the game modules award points. I'm going with the latter since I'm adding swappable functionality to my already existing modules.

Later I will release a sample sgm_vote module that chooses the next game based on player votes and an updated version of my fg_ctf module. The CTF module will have support for the swappable game interface and also remain backwards compatible (read: the game will run automatically as usual unless a Swappable=1 setting is present).

Edit: fixed copy/paste mistake.
Animate Dreams - Sun Jun 10, 2007 1:12 pm
Post subject:
Lol, I did something like that, once. I even got it working, but it was one monolithic module, and... well, it didn't work well. But, um... was source supposed to come with your post?

Lol, I think I already found a bug:

#endi

^ Doesn't look right to me. =\
Solo Ace - Sun Jun 10, 2007 1:24 pm
Post subject:
#endTheWhiningAni
Smong - Sun Jun 10, 2007 3:50 pm
Post subject:
I'll post source to the game manager and fg_ctf later, I'm currently still tweaking them.
Smong - Fri Jun 15, 2007 6:36 am
Post subject:
Here's an example sgm_vote module. It adds the command ?newgame (everything is run automatically, but mods may wish to reset the game). This demo uses the latest fg_ctf (v1.9).

I did consider defining the "game type" modules in the settings, but left them in the code to prevent people screwing up the settings.
Code: Show/Hide
#include "fg_ctf.h"

#define GAME_COUNT 2

local const struct
{
   const char *iid;
   const char *votename;
   const char *helptext;
} game_info[] =
{
   /* edit this and GAME_COUNT to add more games */
   { I_SWAPPABLEGAME_CTF, "CTF", "Bring the enemy flag to your base" },
   { I_SWAPPABLEGAME_CTF, "CTF", "Bring the enemy flag to your base" },
};

The actual game interface is loaded dynamically just before the game is started.
All times are -5 GMT
View topic
Powered by phpBB 2.0 .0.11 © 2001 phpBB Group