Difference between revisions of "How to approach modding"

From Cube Wiki
Jump to: navigation, search
(No difference)

Latest revision as of 17:59, 12 December 2014

Modding Sauerbraten

This is in contrast to How NOT to start a mod. If you would like to try yourself at writing additional code to the current (or -- don't, please! -- old release based) source you've come to the right page. The following examples are based off the 2007-09-18 Summer release and have become relatively obsolete. They're here more as "in the broad strokes" examples.

First we'll add getyaw, which is good as a command for editors; helping to orientate when they've forgotton which way the sun is in this skybox or are underground. It's like a compass.

With the second modification we'll add ourselves a new command that gives us a shortcut from hunting down specific textures from unspecified sets to add them with shaders to our own map config... it outputs path-to-texture.

Finally, the most contraversial modification, it has certain undeniable benefits... but in it's current state also it's drawbacks. If you really think about the issues at hand I hope this example helps you avoid underestimating implications of your ideas before you invest time into something that turns out to require a better idea...

Following the examples

First create a backup of any file before you edit it.



File: We're going to modify src/fpsgame/client.h. Goal: Easy access to orientation.

CCOMMAND(getyaw, "", (clientcom *self), intret((int)self->player1->yaw)); // MeatROme

I suggest you place this line after the one defining getteam, before the closing curly-bracket below that. A modification can be very simple. Use it in your CubeScript:

echo [I'm pointing due (concatword (getyaw) ".")]


File: We're going to modify src/engine/octaedit.cpp Goal: Easy access to texture paths/namesUsage: CubeScript: echo (gettexname)

 void gettexname()
     if(noedit()) return;
     int cti = -1;
     loopxyz(sel, sel.grid, cti = c.texture[sel.orient]);
     loopi(curtexnum) if(texmru[i]==cti)
         Slot &slot = lookuptexture(texmru[i], false);
         if(slot.loaded) conoutf("%d : %s", i, slot.sts[0].name);
 COMMAND(gettexname, ""); // MeatROme

This code should end up somewhere close to the definitions for edittex and gettex. Use it in the console, bind yourself a key to it; use a result-a-string approach like getyaw if you want to process it further with CubeScript, but for general info a conoutf seemed most appropriate.


File: We're going to modify src/engine/rendertext.cpp. Goal: Vasic INTL8 awareness, so that the engine doesn't ignore special chars (such as €, ä, Ü, ß...) Usage: Automatic

.. right in front of the implementation of draw_text you should add:

 static int bcc = 0; // boguscharcount

and then replace the two lines

         c -= 33;
         if(!curfont->chars.inrange(c)) continue;

with this

// MeatROme:
bcc += (c<0 || c>127) ? 1 : 0; //if(bcc) printf(" [%2d:%+4d: %c ]    ", bcc, c, c);

c -= 33;    // original

if ( ! curfont->chars.inrange(c) ) // continue; original
if ( ! bcc ) continue;
c = curfont->chars.length() - 1; // assume last char is /bogus char/
glColor4ub(200, 96, 96, a);

For this to work as intended you should add a specific "bogus" char to your data/font.cfg. If you don't do anything it will pick the tilde "~" which might be to inconspicious, use the "#" with

fontchar 52  0   35     // #:bogus char

this suggested default bogus char - or paint your own into some of the remaining space and give those coords.

If you have keys not keymapped for sauerbraten it won't show their occurence in the console. E.g. german Umlaut characters "Ö", "Ü", "ä" ("ä") for example aren't shown in-game, but your text output will show them.

This modification makes them apparent in-game too; so you won't wonder whereever you typed that hitherto invisible character inside your console width spanning on-the-fly script.

Did you ever get an "unknown command 'map'" error? It was probably due to a special (= invisible) character in the input.

But it's usage/display is somewhat lacking the way this is done ... better to rethink the approach ...


Notice how I marked all my changes - this is a licensing requirement! Hope I got you onto the tracks with this, have fun!