Development > Coding

Coding tips & FAQ

(1/2) > >>


You should submit a patch to our tracker (make sure to read our coding guidelines. Once you have submitted a patch that was accepted, you can get also write access to our svn. All you need is am account at

We also have some sections in our wiki with more information: Contribute article and especially: the coding article.


Mattn told me that there exists a print-command for debug messages. The syntax is the nearly same as printf. You can use it like this:

--- Code: ---Com_DPrintf(DEBUG_CLIENT, "Your debug message here.\n");

Com_DPrintf(DEBUG_CLIENT, "Your debug message here id='%i'\n" , some_integer_number );
--- End code ---
I suggest to add the current function name in front of the actual message, to locate the function faster and keep the messages seperated from the others.

These messages are only displayed if you start UFO:AI like this:

--- Code: ---./ufoai +set developer 1
--- End code ---
... or when you enter ...

--- Code: ---+set developer 1
--- End code ---
... in the in-game console.


'Clean' string handling in ufo:ai code

Initializing strings

--- Code: ---char string[BUFFER_SIZE]; // BUFFER_SIZE may have a different name
string[0] = '\0';
--- End code ---

Checking for initialized strings

--- Code: ---if (stringVar[0] != '\0') {
/* string is not empty */
} else {
/* string is zero/empty */
--- End code ---

Copy strings

--- Code: ---Com_sprintf(string, BUFFER_SIZE, "teststring %s: %i", something->name, thisIsInt);
Com_sprintf(string, sizeof(string), "teststring %i", intNumber);
--- End code ---

--- Code: ---Q_strncpyz(string, thisIsAnotherStringPointer, BUFFER_SIZE);
--- End code ---

Compare strings

--- Code: ---if (!Q_strncmp(string, "test", 4)) {
/* string has "test" in it */
--- End code ---
When using Q_strncmp you have to keep in mind, that string like testSomethingOtherVeryLongHere also match on the above Q_strncmp call.


EDIT: removed gettext example


What about variable naming? function naming? Proposing:

structs -> lower case
functions -> PART_CapitalizeNames, where PART is the name of the unit the function belongs too.
eg AIR -> arircraft
constants -> UPPERCASE
variables -> lowerAndUppercaseNames

use tabs, not spaces

never use one line conditials

--- Code: ---//DONT
if(happy) clappYourHands;
//instead use
if(happy) {

--- End code ---

It was well hidden but i found this

Another thing, related to FAQ, "How to submit a patch":

Before you add a new patch, please make sure you have done so on the latest version of the branch you are working on. use "svn up" to update and check for conflicts.
Make a diff of the src

--- Code: ---svn diff src/ > filename.diff

--- End code ---
In the SF page of ufo:ai , there is a patch tracker which is meant to keep track of all patched. (thus you need to have registered on Now you can create a new tracker by providing a description and the diff file. You will be mailed for every change in the tracker.


[0] Message Index

[#] Next page

Go to full version