Game Development Community

Cleanly scripting game types.

by Phil Carlisle · in Torque Game Engine · 03/27/2002 (3:15 am) · 8 replies

Ok, I'm not leet scriptzor. Not in any way shape or form.

Ive hacked some script together to play Realm Wars a bit team play ish. But now I'm looking to change it so that we arent quite so hard-coded.

There are many different multiplayer game styles, with many different conditions for winning.

I'm trying to think through the best method to support them all. I keep coming back to packages, but I really have no clue how they work.

Also, how do we handle more than 2 teams for instance?

Anyway, I'd like to get your feedback on possible ways to structure the script code so that we can have all styles of gameplay? for instance, here's an idea.

Make a list of all possible game win conditions, write a single script that literally handles any combination of those win conditions via a function. Have packages that then override this script to handle win conditions differently.

So for instance, the script will have functions like:

onObjectiveCaptured
onGameTimeExpired
onFlagCaptured

When any of these things occur, the code calls the function. The function may ignore different conditions based on what game mode it is.

The mission would then have a string which denotes which "GameRule" package to activate.

How did the different game rules work in T2 btw? is it even possible to do with 1 class?

Phil.

#1
03/27/2002 (4:20 am)
In my opinion, it would be much better to use a system similiar to T2's game code system.

How it works is like so.

When a mission is loaded a game object is created with the SuperClass of DefaultGame and a Class of, in this case, CnHGame.

The defaultgame functions have the bulk of your code in them.
eg. team changing
function DefaultGame::changeTeam(%game, %client, %team)
{
   echo("running DefaultGame here");
}

In your code to call this function you simply use
Game.changeTeam(%client, %team);
or
%game.changeTeam(%client, %team); (if you know %game)

Should this mission type wish to overwrite or add to this code it is a simple matter of doign somethign like this.

function CnHGame::changeTeam(%game, %client, %team)
{
    echo("running CnhGame here");
    parent::changeTeam(%game, %client, %team);
}

or

function CnHGame::changeTeam(%game, %client, %team)
{
    echo("overwrite here");
}

Then any time you call Game.changeTeam(%client, %team) it uses the Class function in lieu of the Superclass function :)

This is how I have Trakers set up and working. Adding a mission type is very simple usign this method cause the base of the code is the same through most mission types.

EDIT: Should you wish a copy of Traker's DefaultGame and Game type scripts for RW just ask :)
#2
03/27/2002 (6:39 am)
i might have not understood.... but i thought tribes2 used packages...
ie fps/game.cs with a default function
when u changed the play mode it would load anohter package, let's say ctf... so ctf package will also have a file ctf/game.cs with the same function above but with different content... so it would override the default game function with the ctf one... tho u can still access the old one using Parent::
Isn't it that way?
#3
03/27/2002 (12:16 pm)
Nope
It uses packages in this system as well for non game functions, but the bulk of the code is done with game classes/superclases
#4
01/13/2003 (9:40 am)
Its been awhile but where do we declare the class and superclass at? In T2 the missons had a "// MissionType CTF CNH" thing in the mis file to declare the type. I have added my type to the MissionInfo part but have yet to figure the class/superClass stuff out.

Sam
#5
01/13/2003 (7:18 pm)
If you download my game Trakers: Bid for Glory, it uses this system and you can copy it if you wish.

www.liquid.nq.net/trakers/
#6
01/14/2003 (10:36 am)
Thanks for the offer Wiz but at 30 megs my poor old 56k modem wont do well.
#7
01/14/2003 (11:06 am)
I use a very simple system for our game.

In game.cs where it loads all the .cs files I have this:

if ($Server::MissionType $= $gametype_conquest)
     exec("./gametypes/Conquest.cs");
   if ($Server::MissionType $= $gametype_ctf)
     exec("./gametypes/CTF.cs");
   if ($Server::MissionType $= $gametype_teamdm)
     exec("./gametypes/TeamDM.cs");
   if ($Server::MissionType $= $gametype_replicatorgauntlet)
     exec("./gametypes/ReplicatorGauntlet.cs");

Then I added function calls into the existing key functions handling player death etc.
These functions are declared in the gametype scripts.

Here's a rough template for such an (incomplete) gametype function:

function sg_reset()
{
    echo ("Starting Replicator Gauntlet");

}

function sg_playerJoinedTeam(%client, %teamid)
{
    %client.spawnPlayer();
}

function sg_playerLeftTeam(%client, %teamnumber)
{
}

function sg_playerDied(%client)
{
}

function sg_capturedObjective(%client, %objective)
{
}

What this does very well is keeping gametype-specific stuff outside of the standard torque scripts. I do all my scoring and respawn stuff like this, for example in "CTF" you can respawn immediately whereas in "Conquest" you respawn in waves like DoD or BF1942.
#8
01/14/2003 (1:36 pm)
Sam,
If you wish me to email you the scripts that do this it is no problem.