UFO AI TD1 Notes

Rendering API

the re variable contains a structure which houses pointers to the rendering API. These values are initialize in the GetRefAPI function, as follows:

        refexport_t     re;

        re.api_version = API_VERSION;

        re.BeginRegistration = R_BeginRegistration;
        re.RegisterModel = R_RegisterModelShort;
        re.RegisterSkin = R_RegisterSkin;
        re.RegisterFont = R_RegisterFont;
        re.RegisterPic = Draw_FindPic;
        re.SetSky = R_SetSky;
        re.EndRegistration = R_EndRegistration;

        re.RenderFrame = R_RenderFrame;

        re.DrawModelDirect = R_DrawModelDirect;
        re.DrawGetPicSize = Draw_GetPicSize;
        re.DrawPic = Draw_Pic;
        re.DrawNormPic = Draw_NormPic;
        re.DrawStretchPic = Draw_StretchPic;
        re.DrawChar = Draw_Char;
        re.DrawPropChar = Draw_PropChar;
        re.DrawPropString = Draw_PropString;
        re.DrawPropLength = Draw_PropLength;
        re.DrawTileClear = Draw_TileClear;
        re.DrawFill = Draw_Fill;
        re.DrawColor = Draw_Color;
        re.DrawFadeScreen = Draw_FadeScreen;

        re.AnimAppend = Anim_Append;
        re.AnimChange = Anim_Change;
        re.AnimRun = Anim_Run;

        re.DrawStretchRaw = Draw_StretchRaw;

        re.Init = R_Init;
        re.Shutdown = R_Shutdown;

        re.CinematicSetPalette = R_SetPalette;
        re.BeginFrame = R_BeginFrame;
        re.EndFrame = GLimp_EndFrame;

        re.AppActivate = GLimp_AppActivate;



How to run ufoai under gdb with emacs

First, make sure that ufo was compiled with debugging enabled. You can do this using the debug target:

bash$ make debug

Next, open a vt, yes a text vt. Change to the ufoai_source/linux directory and start emacs

Start gdb within emacs using the M-x gdb command, and select the ufo executable as your target, for instance

gdb ~/projects/ufoai/ufo

Set a breakpoint at the first function in the main(), like this:

(gdb) b sys_linux.c:298

And use the run command:

(gdb) run

Now you're cooking!

The Initialization Process

The init process looks something like this:

\-- main
|   \-- Qcommon_Init
|   |   \-- COM_InitArgv
|   |   \-- Swap_Init
|   |   \-- Cbuf_Init
|   |   |   \-- SZ_Init
|   |   \-- Cmd_Init
|   |   \-- Cvar_Init
|   |   \-- Key_Init
|   |   \-- Cbuf_AddEarlyCommands
|   |   \-- Cbuf_Execute
|   |   \-- FS_InitFilesystem
|   |   \-- Sys_Init
|   |   \-- NET_Init
|   |   \-- Netchan_Init
|   |   \-- SV_Init
|   |   |   \-- SV_InitOperatorCommands
|   |   |   \-- SZ_Init
|   |   \-- CL_Init
|   |   |   \-- Con_Init
|   |   |   \-- S_Init
|   |   |   |   \-- SNDDMA_Init
|   |   |   \-- VID_Init
|   |   |   |   \-- VID_CheckChanges
|   |   |   \-- V_Init
|   |   |   \-- SCR_Init
|   |   |   |   \-- SCR_TouchPics
|   |   |   \-- CDAudio_Init
|   |   |   \-- CL_InitLocal
|   |   |   |   \-- Sys_Milliseconds
|   |   |   |   \-- Con_CheckResize
|   |   |   |   |   \-- Con_ClearNotify
|   |   |   |   \-- Com_InitInventory
|   |   |   |   \-- CL_InitInput
|   |   |   |   \-- MN_ResetMenus
|   |   |   |   \-- CL_ResetParticles
|   |   |   |   \-- CL_ResetTeams
|   |   |   |   \-- CL_ResetCampaign
|   |   |   |   \-- CL_ResetSequences
|   |   |   \-- IN_Init
|   |   |   \-- FS_ExecAutoexec
|   |   \-- Com_ParseScripts



void normpath(char *path)
qcommon/files.c

path is a pointer to a zero terminated string.
This function changes all “\” characters to “/” characters and all upper case characters to lower case characters.

char **FS_ListFiles( char *findname, int *numfiles, unsigned musthave, unsigned canthave )
qcommon/files.c

returns a pointer to an array of string pointers. Each of these string pointers points to a file matching findname. The musthave and canthave argument describe file attributes.




The scripting/menu system

The UFOAI scripting system is really cool. By manipulating the scripts in the ufos directory you can customize the game to do just about anything (ok, it won't make coffee). This document explains how it works.

Files

UFOAI TD1 reads every file in the ufos directory that ends in .ufo (i.e., matches the pattern “ufos/*ufo”).

Script Objects

The scripts define a set of objects. Some objects are more complicated than others. Some objects reference other objects. Every object has a type and a name. There are a limited number of object types:



object_type object_name
{
  object_type  object_value
  object_type  object_name
  {
     object_type object_value
  }
}

Valid object types are:

menu





zone





invis

true/false


pic





image

path/file



pos

“x y” position of upper left corner



texl

“x y”



texh

“x y”



click

{cmd “mn_push singleplayer” }



out

{ *button_singleplayer texl "0 0" *button_singleplayer texh "256 64"



in

{ *button_singleplayer texl "0 64" *button_singleplayer texh "256 128" }


string





string

“*cvar ver”



pos

“x y” position of upper left corner


func





cmd

“command string”

actors




gender
(may be male, female or neutral)

{ list of models }
each element of the model list takes the form:
directory body_file head_file
where directory is relative to base/models

names




gender
(male, female, neutral or lastname)

{ list of names }
use of quotes is permitted but not required

team




actors_name
must match an actors object.

item




name

“name”


model

path
path is relative to base/models


type

??? seems to be one of rifle, ammo, pistol rpg, or biggun


category

??? seems to be 0 or 1. All category 1 objects seem to be weapons, while category 0 seem to be ammo


shape

“s t x y”


center

“s t f”


scale

f


ammo

x


reload

x


price

x


buytype

??? 0


primary

an unnamed object, with member objects as follows:



name

“name”



projtl

particle_name
must match a defined particle object



impact

???



firesnd

path/filename
relative to base/sounds



speed

x



spread

“x y”



crouch

f



range

x



shots

x



ammo

x



rof

x



time

x



damaage

“x y”


secondary

another unnamed object, with member objects same as primary

equipment




item_name

quantity

mission




text

“description of mission”
semi-colons denote line feeds


map

map_file
must be defined in base/maps


music

music_file
must be defined in base/music


pos

“x y” ???


aliens

x
number of aliens to spawn


civilians

number of civilians to spawn


alien_equip

equipment_name
corresponds to a defined equipment object


recruits

x
number of new recruits which join after successful completion of the mission


$win

x
reward for successfully completing the mission


$alien

x
bonus for each alien killed


$civilian

x
bonus for each civilian saved

campaign




team

team_name (must be defined by a team object)


soldiers

num


equipment

equipment_name
corresponds to a previously defined equipment object


market

market_name


credits

x


mission_name
correponds to a mission object

“mission_name”
this property is optional. It defines a pre-requisite mission which must be completed before this mission is available

inventory




shape

“x x x x”
there must be at least one shape line. There may be more than one shape lines


single

true or false


in

x


out

x



Buttons:

A simple backgroung image can be place using a pic like this:

{
  image menu/main_ul
  pos   "0 0"
}       



A button is defined using a more complicate pic object type, like this:

pic button_singleplayer
{
  image  menu/main_buttons1
  pos    "640 170"
  texl   "0 0"
  texh   "256 64"
  click  { cmd "mn_push singleplayer" }
  out    { *button_singleplayer texl "0 0"  *button_singleplayer texh "256 64" }
  in     { *button_singleplayer texl "0 64" *button_singleplayer texh "256 128" }
}



Special Functions:

The init function is automatically executed when a menu is pushed to the screen.