http://ufoai.org/w/index.php?title=User:Bayo/script&feed=atom&action=historyUser:Bayo/script - Revision history2024-03-28T22:53:04ZRevision history for this page on the wikiMediaWiki 1.35.4http://ufoai.org/w/index.php?title=User:Bayo/script&diff=40007&oldid=prevBayo: /* Values */2012-06-09T10:02:49Z<p><span dir="auto"><span class="autocomment">Values</span></span></p>
<p><b>New page</b></p><div>UFO:AI scripts, inside <code>.ufo</code> files, are used to define most of the content of the game. <br />
<br />
Yet, there is no global parser for this kind of files. Each node type use is own code to read one by one token and use them like it want. Then here some construction rules, scripts should respect to unify our scripts. It was not created from scratch, but from script legacy, with patch here and there to allow unifying and avoid most of ambiguous constructions.<br />
<br />
This grammar is already used by our Eclipse plugin, to parse and validate scripts.<br />
<br />
But all scripts are not yet conform to that.<br />
<br />
==Grammar==<br />
<pre><br />
UFOSCRIPT := NODE*<br />
<br />
NODE := TYPE IDENTIFIER? BLOCK<br />
| TYPE IDENTIFIER? LIST<br />
| TYPE VALUE<br />
<br />
BLOCK := '{' NODE* '}'<br />
<br />
LIST := '(' VALUE* ')'<br />
<br />
VALUE := NUMBER | QUOTED_STRING | NAMED_CONST | REFERENCE<br />
<br />
TYPE := NAME<br />
IDENTIFIER := NAME<br />
REFERENCE := NAME<br />
<br />
----<br />
<br />
NAME := [a-z][a-zA-Z0-9/\-_\.]*<br />
<br />
NUMBER := [0-9.]+<br />
<br />
QUOTED_STRING := '"' -> '"'<br />
<br />
NAMED_CONST := [A-Z][A-Z_]*<br />
</pre><br />
This grammar is simplified to stay readable. But some construction may not be allowed.<br />
<br />
==Values==<br />
{| class="ufotable"<br />
! NUMBER<br />
| A number, like <code>6</code>, or <code>56.2</code><br />
|-<br />
! QUOTED_STRING<br />
| Any kind of content between to double quotes. It support common C escaping, like <code>\n</code>, <code>\"</code>. Many composite types are also quoted, for example <code>"2.5 4.0 2.5"</code> which is a 3D vector; or <code>"1 0 0 0.5"</code> which can be a red color with some transparency.<br />
|-<br />
! NAMED_CONST<br />
| A named constant provided by the game. It must be in full upper case, for example <code>EMPL_PILOT</code>, and usualy there is only a set of available values. It should be always used when a value is hardcoded into the game (instead of a quoted string).<br />
|-<br />
! IDENTIFIER<br />
| An unique identifier of the script object.<br />
|-<br />
! REFERENCE<br />
| A reference to an unique identifier provided somewhere else in the script.<br />
|}<br />
<br />
==Structure==<br />
<br />
===Block===<br />
A block contains sub nodes, which can contains another blocks. Usualy it is used like a set of properties (key-value structure). But it can be used like a sequence of definitions.<br />
<br />
<pre><br />
item armour_light<br />
{<br />
name "_Combat Armour"<br />
image "armour/light"<br />
center "0 0 -5"<br />
...<br />
<br />
protection<br />
{<br />
normal_light 20<br />
normal_medium 18<br />
normal_heavy 12<br />
...<br />
}<br />
<br />
rating<br />
{<br />
normal 30<br />
blast 30<br />
fire 20<br />
...<br />
}<br />
}<br />
</pre><br />
<br />
Block can be identified by an id. Which is the case for most block from the root, but not only.<br />
<br />
Bellow, <code>intro</code> identify the <code>sequence</code> block, and <code>i_sentence1</code> identify one <code>obj2d</code> block. We also can see the script refer to that localy defined block.<br />
<pre><br />
sequence intro<br />
{<br />
...<br />
<br />
obj2d i_sentence1<br />
{<br />
text "_intro_sentence1"<br />
pos "512 100"<br />
align "uc"<br />
color "0.2 1 0.5 0"<br />
fade "0 0 0 0.5"<br />
speed "0 0"<br />
relative false<br />
}<br />
<br />
...<br />
<br />
rem i_sentence1<br />
}<br />
</pre><br />
<br />
===List===<br />
A list contains a set of values. It can not contain a block or a list. But number, string, const or references.<br />
<br />
Some script use it to define a "real" list of values<br />
<pre><br />
mapdef africa_large<br />
{<br />
map "+africa"<br />
<br />
...<br />
<br />
gametypes ( fight1on1 fight2on2 coop2 coop3 coop4 )<br />
<br />
...<br />
<br />
aircraft ( craft_drop_firebird craft_drop_herakles craft_drop_raptor )<br />
ufos ( craft_ufo_harvester )<br />
terrains ( "grass" "tropical" "desert" "mountain" )<br />
<br />
...<br />
}<br />
</pre><br />
<br />
<br />
Others use it like a tuple to define a composite object. In this kind of way it can be better to use a block. At least you should think about the two ways. A block is more verbose but it is self descriptive and more easy to custom.<br />
<pre><br />
equipment multiplayer_initial<br />
{<br />
name "_Multiplayer"<br />
item (assault 10)<br />
item (assault_ammo 13)<br />
item (machinegun 1)<br />
...<br />
}<br />
</pre></div>Bayo