Difference between revisions of "WML Templates"

From The Battle for Wesnoth Wiki
(Units and scenarios still to do. Still needs sanity checking.)
m (bit of tidying)
Line 1: Line 1:
 
 
This page provides a set of blank 'templates' which can be used as a basis
 
This page provides a set of blank 'templates' which can be used as a basis
 
for user-made campaigns, scenarios, and units. You will need to have a basic
 
for user-made campaigns, scenarios, and units. You will need to have a basic
Line 15: Line 14:
 
directories as well. These examples will lead you through the basic setup of
 
directories as well. These examples will lead you through the basic setup of
 
a campaign called ''Example_Campaign''. You will need to replace all
 
a campaign called ''Example_Campaign''. You will need to replace all
occurrences of 'Example_Campaign' with the name of your own campaign.
+
occurrences of ''Example_Campaign'' with the name of your own campaign.
  
 
For everything to work reliably, the names must be ''exactly'' as shown. If
 
For everything to work reliably, the names must be ''exactly'' as shown. If
Line 26: Line 25:
  
 
For Linux users, all paths are relative to
 
For Linux users, all paths are relative to
'''/home/username/.wesnoth/data/campaigns/''', where 'username' will be the
+
''/home/username/.wesnoth/data/campaigns/'', where ''username'' will be the
 
currently logged-in user. The game has been organised so that you can keep
 
currently logged-in user. The game has been organised so that you can keep
 
your own data separate from the main Wesnoth data, which means your custom
 
your own data separate from the main Wesnoth data, which means your custom
 
campaigns will not interfere with the workings of the rest of the game, and
 
campaigns will not interfere with the workings of the rest of the game, and
 
ensures that you should never need to alter anything inside the main Wesnoth
 
ensures that you should never need to alter anything inside the main Wesnoth
folder (usually /usr/local/share/wesnoth or similar).
+
folder (usually ''/usr/local/share/wesnoth'' or similar).
  
 
For Mac users, [need correct information; may vary from version to version]
 
For Mac users, [need correct information; may vary from version to version]
Line 43: Line 42:
 
follows:
 
follows:
  
*A blank text file: /Example_Campaign.cfg
+
*A blank text file: ''/Example_Campaign.cfg''
*A campaign folder: /Example_Campaign/
+
*A campaign folder: ''/Example_Campaign/''
*A scenario folder: /Example_Campaign/scenarios/
+
*A scenario folder: ''/Example_Campaign/scenarios/''
*A maps folder: /Example_Campaign/maps/
+
*A maps folder: ''/Example_Campaign/maps/''
*A units folder: /Example_Campaign/units/
+
*A units folder: ''/Example_Campaign/units/''
*An images folder: /Example_Campaign/images/
+
*An images folder: ''/Example_Campaign/images/''
*A utilities (macros) folder: /Example_Campaign/utils/
+
*A utilities (macros) folder: ''/Example_Campaign/utils/''
 +
 
 +
*At least one scenario file: ''/Example_Campaign/scenarios/01_First_Scenario.cfg''
 +
*As many maps as scenarios: ''/Example_Campaign/maps/01_First_Scenario.map''
 +
*Inside the utils folder, a blank text file: ''/utils.cfg''
 +
*Inside the utils folder, a blank text file: ''/deaths.cfg''
 +
*Inside the utils folder, a blank text file: ''/route.cfg''
 +
*Inside the utils folder, a blank text file: ''/story.cfg''
  
*At least one scenario file: /Example_Campaign/scenarios/01_First_Scenario.cfg
 
*As many maps as scenarios (covered elsewhere). These maps will usually be
 
called /Example_Campaign/maps/01_First_Scenario.map, 02_Second_Scenario.map
 
and so on, but there may be exceptions.
 
*Inside the utils folder, a blank text file: /utils.cfg
 
*Inside the utils folder, a blank text file: /deaths.cfg
 
*Inside the utils folder, a blank text file: /route.cfg
 
*Inside the utils folder, a blank text file: /story.cfg
 
  
 
'''Tip:''' Number your scenarios as the first part of their filenames. This
 
'''Tip:''' Number your scenarios as the first part of their filenames. This
 
makes it easier to tell what order they will be used in. If your scenarios
 
makes it easier to tell what order they will be used in. If your scenarios
 
branch (meaning a player will ''either'' play scenario A ''or'' scenario B,
 
branch (meaning a player will ''either'' play scenario A ''or'' scenario B,
but not both), label the alternatives something like 03a_First_Branch.cfg,
+
but not both), label the alternatives something like
03b_Second_Branch.cfg and so on. For a basic campaign, we advise you not to
+
''03a_First_Branch.cfg'', ''03b_Second_Branch.cfg'' and so on. For a basic
use scenario branching unless you're already a confident WML coder.
+
campaign, we advise you not to use scenario branching unless you're already
 +
a confident WML coder.
  
 
'''Tip:''' Use the same numbering scheme for your maps as well, although if
 
'''Tip:''' Use the same numbering scheme for your maps as well, although if
 
you want to name the maps differently from the corresponding scenario,
 
you want to name the maps differently from the corresponding scenario,
that's fine. For example, you might have a scanerio called
+
that's fine. For example, you might have a scenario called
 
''01_Kidnap_Attempt.cfg'', while the associated map is called
 
''01_Kidnap_Attempt.cfg'', while the associated map is called
 
''01_The_Royal_Park.map''.
 
''01_The_Royal_Park.map''.
Line 81: Line 80:
 
for these folders to find your scenarios, images etc. If you use a different
 
for these folders to find your scenarios, images etc. If you use a different
 
folder arrangement of your own (for example if you store all your macros in
 
folder arrangement of your own (for example if you store all your macros in
a /macros/ directory) then you will have to adjust the example code
+
a ''/macros/'' directory) then you will have to adjust the example code
 
accordingly.
 
accordingly.
  
'''Tip:''' Also choose an abbreviation for your campaign that doesn't clash
+
'''Tip:''' Choose an abbreviation for your campaign that doesn't clash
with the names of any other campaign. For example, Heir to the Throne is
+
with the names of any other campaign. For example, ''Heir to the Throne'' is
commonly abbreviated HTTT. If your campaign is called 'An Example Campaign',
+
commonly abbreviated ''HTTT''. If your campaign is called ''An Example
use AEC. This is useful because you can then prepend 'AEC' to your
+
Campaign'', use ''AEC''. This is useful because you can then prepend ''AEC''
campaign-specific macros and avoid accidental name clashes with WML code
+
to your campaign-specific macros and avoid accidental name clashes with WML
from other campaigns.
+
code from other campaigns.
  
  
 
=== Example_Campaign.cfg, [Campaign] section ===
 
=== Example_Campaign.cfg, [Campaign] section ===
  
The Example_Campaign.cfg file has two parts. The first part determines the
+
The ''Example_Campaign.cfg'' file has two parts. The first part determines
available difficulty settings and difficulty descriptions for your campaign.
+
the available difficulty settings and difficulty descriptions for your
Without this data, your campaign will not appear in the Wesnoth menu, and
+
campaign. Without this data, your campaign will not appear in the Wesnoth
you won't be able to select it for playing. The difficulty settings are
+
menu, and you won't be able to select it for playing. The difficulty
listed between a [campaign] and a [/campaign] tag as shown below. The parts
+
settings are stored between a ''[campaign]'' and a ''[/campaign]'' tag as
marked '''in bold''' are the bits you will need to customise:
+
shown below. The parts marked '''in bold''' are the bits you will need to
 +
customise:
  
 
  [campaign]
 
  [campaign]
Line 106: Line 106:
 
  define='''EXAMPLE_CAMPAIGN'''
 
  define='''EXAMPLE_CAMPAIGN'''
 
  first_scenario='''First_Scenario'''
 
  first_scenario='''First_Scenario'''
 
+
<br>
 
  difficulties=EASY,NORMAL,HARD
 
  difficulties=EASY,NORMAL,HARD
 
  difficulty_descriptions={MENU_IMG_TXT2 '''Easy_Image.png'''
 
  difficulty_descriptions={MENU_IMG_TXT2 '''Easy_Image.png'''
Line 114: Line 114:
 
  + {MENU_IMG_TXT2 '''Hard_Image.png'''
 
  + {MENU_IMG_TXT2 '''Hard_Image.png'''
 
  _"'''Hard setting description'''" _"(Hard)"}
 
  _"'''Hard setting description'''" _"(Hard)"}
 
+
<br>
 
  icon='''Campaign_Icon.png'''
 
  icon='''Campaign_Icon.png'''
 
  description= _ "'''This is an example campaign template, all ready to be
 
  description= _ "'''This is an example campaign template, all ready to be
customised.'''"
+
customised.'''"
 
+
<br>
 
   [about]
 
   [about]
 
   title= _ "Campaign Designer"
 
   title= _ "Campaign Designer"
 
   text="'''Your Name'''"
 
   text="'''Your Name'''"
 
   [/about]
 
   [/about]
 
+
<br>
 
   [about]
 
   [about]
 
     title= _ "Current Maintainer"
 
     title= _ "Current Maintainer"
 
     text="'''Your Name'''"
 
     text="'''Your Name'''"
 
   [/about]
 
   [/about]
 
+
<br>
 
  [/campaign]
 
  [/campaign]
  
Line 150: Line 150:
 
  define='''EXAMPLE_CAMPAIGN'''
 
  define='''EXAMPLE_CAMPAIGN'''
  
We will call this important entry the ''campaign name key''. The #ifdef
+
We will call this important entry the ''campaign name key''. The ''#ifdef''
command used in section 3 must exactly match whatever you define here.
+
command used in the next section must exactly match whatever you define here.
  
  
Line 177: Line 177:
 
There are six different things you can customise here. The Easy, Normal and
 
There are six different things you can customise here. The Easy, Normal and
 
Hard setting descriptions are usually set to an atmospheric name for the
 
Hard setting descriptions are usually set to an atmospheric name for the
corresponding difficulty level. For example, you might use 'Scout' for the
+
corresponding difficulty level. For example, you might use ''Scout'' for the
easiest setting, 'Warrior' for the middle setting, and 'General' for the
+
easiest setting, ''Warrior'' for the middle setting, and ''General'' for the
 
hardest setting. As a rough guide, you should limit yourself to 1-3 words
 
hardest setting. As a rough guide, you should limit yourself to 1-3 words
for each difficulty description. The Easy_Image.png, Normal_Image.png and
+
for each difficulty description. The ''Easy_Image.png'',
Hard_Image.png refer to custom graphics for each difficulty level. Normally
+
''Normal_Image.png'' and ''Hard_Image.png'' refer to custom graphics for
you would save these in the /Example_Campaign/images/ folder. You can also
+
each difficulty level. Normally you would save these in the
use any standard Wesnoth graphic. For example, if you wanted to use the
+
''/Example_Campaign/images/'' folder. You can also use any standard Wesnoth
image of an orcish archer for one of the difficulty settings, you would give
+
graphic. For example, if you wanted to use the image of an orcish archer for
the filename as units/orcs/archer.png
+
one of the difficulty settings, you would give the filename as
 +
''units/orcs/archer.png''
  
  
Line 192: Line 193:
 
A custom campaign icon is optional. If you want to use a standard Wesnoth
 
A custom campaign icon is optional. If you want to use a standard Wesnoth
 
image, provide the path from the main Wesnoth images directory. For example,
 
image, provide the path from the main Wesnoth images directory. For example,
items/monolith3.png
+
''items/monolith3.png''. Otherwise Wesnoth will look in the
 
+
''/Example_Campaign/images/'' folder, in this example for a png file called
Otherwise Wesnoth will look in the /Example_Campaign/images/ folder, in this
+
''Campaign_Icon.png''.
example for a png file called Campaign_Icon.png
 
  
  
 
  description= _ "'''This is an example campaign template, all ready to be
 
  description= _ "'''This is an example campaign template, all ready to be
customised.'''"
+
customised.'''"
  
 
The campaign description is also free-text. This is a chance to give a quick
 
The campaign description is also free-text. This is a chance to give a quick
Line 210: Line 210:
 
     text="'''Your Name'''"
 
     text="'''Your Name'''"
 
   [/about]
 
   [/about]
 
+
<br>
 
   [about]
 
   [about]
 
     title= _ "Current Maintainer"
 
     title= _ "Current Maintainer"
Line 235: Line 235:
 
loading ''all'' the images, macros, units etc. from all available campaigns
 
loading ''all'' the images, macros, units etc. from all available campaigns
 
might take a very long time and might cause errors, so when Wesnoth first
 
might take a very long time and might cause errors, so when Wesnoth first
starts it only reads the data stored between [campaign] tags.
+
starts it only reads the data stored between the ''[campaign]'' and
 
+
''[/campaign]'' tags.
Remember the line
 
 
 
define=EXAMPLE_CAMPAIGN
 
  
? When a particular campaign is selected by the player, Wesnoth starts
+
Remember the line ''define=EXAMPLE_CAMPAIGN'', which we highlighted as being
loading all the rest of the data for that particular campaign. But for
+
important? When a particular campaign is selected by the player, Wesnoth
Wesnoth to do this, the ''campaign name key'' and the campaign data must
+
starts loading all the rest of the data for that particular campaign. But
 +
for Wesnoth to do this, the ''campaign name key'' and the campaign data must
 
match up correctly. Assuming they do, all the scenario code found by Wesnoth
 
match up correctly. Assuming they do, all the scenario code found by Wesnoth
 
matching the campaign name key will be run. And that is what the lines of
 
matching the campaign name key will be run. And that is what the lines of
Line 250: Line 248:
  
 
  #ifdef '''EXAMPLE_CAMPAIGN'''
 
  #ifdef '''EXAMPLE_CAMPAIGN'''
 
+
<br>
 
  [binary_path]
 
  [binary_path]
    path=data/campaigns/'''Example_Campaign'''
+
path=data/campaigns/'''Example_Campaign'''
 
  [/binary_path]
 
  [/binary_path]
 
+
<br>
 
  # Load campaign utilities first
 
  # Load campaign utilities first
 
  {@campaigns/'''Example_Campaign'''/utils}
 
  {@campaigns/'''Example_Campaign'''/utils}
 
+
<br>
 
  # Add custom units
 
  # Add custom units
 
  [+units]
 
  [+units]
  {@campaigns/'''Example_Campaign'''/units}
+
{@campaigns/'''Example_Campaign'''/units}
 
  [/units]
 
  [/units]
 
+
<br>
 
  # Add scenarios
 
  # Add scenarios
 
  {@campaigns/'''Example_Campagn'''/scenarios}
 
  {@campaigns/'''Example_Campagn'''/scenarios}
 
+
<br>
 
  #endif
 
  #endif
  
Line 274: Line 272:
 
  #ifdef '''EXAMPLE_CAMPAIGN'''
 
  #ifdef '''EXAMPLE_CAMPAIGN'''
  
This must match the define=EXAMPLE_CAMPAIGN from section 1.
+
This must match the ''define=EXAMPLE_CAMPAIGN'' from the ''[[campaign]]''
 +
section.
  
  
 
  [binary_path]
 
  [binary_path]
    path=data/campaigns/'''Example_Campaign'''
+
path=data/campaigns/'''Example_Campaign'''
 
  [/binary_path]
 
  [/binary_path]
  
The [binary_path] tag tells Wesnoth where the images/, units/, scenarios/,
+
The ''[binary_path]'' tag tells Wesnoth where the ''images/'', ''units/'',
maps/ and utils/ folders are.
+
''scenarios/'', ''maps/'' and ''utils/'' folders are.
  
  
Line 304: Line 303:
 
  # Add custom units
 
  # Add custom units
 
  [+units]
 
  [+units]
  {@campaigns/'''Example_Campaign'''/units}
+
{@campaigns/'''Example_Campaign'''/units}
 
  [/units]
 
  [/units]
  
These lines load all the custom units for the campaign. ('# Add custom
+
These lines load all the custom units for the campaign. (''# Add custom
units' is just another free-text comment.)
+
units'' is just another free-text comment.)
  
  
Line 314: Line 313:
 
  {@campaigns/'''Example_Campaign'''/scenarios}
 
  {@campaigns/'''Example_Campaign'''/scenarios}
  
Another comment, then a line that tells Wesnoth to find all the campaign
+
Another comment, then a line that tells Wesnoth where to find all the
scenarios.
+
campaign scenarios.
  
  
 
  #endif
 
  #endif
  
The #ifdef at the start of section 2 is a special multi-line instruction
+
The ''#ifdef'' at the start of this section is a special multi-line
which must be closed using an #endif tag.
+
instruction which must be closed using an ''#endif'' tag.
  
  
Line 345: Line 344:
 
  # A simple map-listing macro
 
  # A simple map-listing macro
 
  # Usage: map={MAP scenario_name.map}
 
  # Usage: map={MAP scenario_name.map}
 
+
<br>
 
  #define MAP MAP_NAME
 
  #define MAP MAP_NAME
 
 
  map_data="{@campaigns/CAMPAIGN_NAME/maps/{MAP_NAME}}"
 
  map_data="{@campaigns/CAMPAIGN_NAME/maps/{MAP_NAME}}"
 
 
  #enddef
 
  #enddef
  
 
'''Usage:''' Just copy-and-paste these five lines of text ''untouched'' into
 
'''Usage:''' Just copy-and-paste these five lines of text ''untouched'' into
 
the utils.cfg file. When you want to use this macro, you call it in your
 
the utils.cfg file. When you want to use this macro, you call it in your
''scenario.cfg'' files, by inserting a line such as
+
''scenario.cfg'' files, by inserting a line such as ''map={MAP
 
+
01_First_Scenario.map}'' or ''map={MAP 02a_Second_Scenario_Branch_A.map}''
map={MAP '''01_First_Scenario.map'''}
+
customising as appropriate to your campaign.
 
 
or
 
 
 
map={MAP '''02a_Second_Scenario_Branch_A.map'''}
 
 
 
or similar, customising the bits in bold as appropriate to your campaign.
 
  
  
 
=== deaths.cfg ===
 
=== deaths.cfg ===
  
This is a macro that will trigger on the death of major campaign
+
This is a macro that will trigger on the death of major campaign characters,
characters, including the heroes. If you only need a few dying speeches, you
+
including the heroes. If you only need a few dying speeches, you could just
could just store the deaths macro inside utils.cfg. If you have more than
+
store the deaths macro inside ''utils.cfg''. If you have more than about
about four, or if you plan for characters to use different dying speeches in
+
four, or if you plan for characters to use different dying speeches in
 
different scenarios, it's probably better to store the deaths macro
 
different scenarios, it's probably better to store the deaths macro
 
separately, as it could get rather long.
 
separately, as it could get rather long.
  
 
  #define '''AEC_DEATHS'''
 
  #define '''AEC_DEATHS'''
 
+
<br>
 
  [event]
 
  [event]
 
  name=die
 
  name=die
Line 389: Line 380:
 
   [/endlevel]
 
   [/endlevel]
 
  [/event]
 
  [/event]
 
+
<br>
 
  [event]
 
  [event]
 
  name=die
 
  name=die
Line 403: Line 394:
 
   [/endlevel]
 
   [/endlevel]
 
  [/event]
 
  [/event]
 
+
<br>
 
  [event]
 
  [event]
 
  name=die
 
  name=die
Line 417: Line 408:
 
   [/endlevel]
 
   [/endlevel]
 
  [/event]
 
  [/event]
 
+
<br>
 
  #enddef
 
  #enddef
  
'''Usage:''' Copy-and-paste this into the deaths.cfg file, and alter the
+
'''Usage:''' Copy-and-paste this into the ''deaths.cfg'' file, and alter the
 
names and final words for each character. If the unit's dying means game
 
names and final words for each character. If the unit's dying means game
 
over for the player, include the section of text that says
 
over for the player, include the section of text that says
Line 438: Line 429:
  
 
If you have additional units who need to speak some final words, just make
 
If you have additional units who need to speak some final words, just make
extra copies of the appropriate section and customise it to suit.
+
extra copies of the appropriate ''[event] &hellip; [/event]'' section and
 +
customise them to suit.
  
  
 
=== story.cfg ===
 
=== story.cfg ===
  
The story.cfg file allows you to collect together all the background plot
+
The ''story.cfg'' file allows you to collect together all the background plot
 
for the campaign in one place. You ''can'' include this data inside the
 
for the campaign in one place. You ''can'' include this data inside the
 
individual scenario files, but it's better coding practice to separate
 
individual scenario files, but it's better coding practice to separate
Line 451: Line 443:
  
 
  #define '''AEC_STORY01'''
 
  #define '''AEC_STORY01'''
 
 
  [story]
 
  [story]
 
   [part]
 
   [part]
Line 458: Line 449:
 
   background='''Background_Image01.png'''
 
   background='''Background_Image01.png'''
 
   [/part]
 
   [/part]
 
 
   [part]
 
   [part]
 
   music='''gameplay02.ogg'''
 
   music='''gameplay02.ogg'''
Line 465: Line 455:
 
   [/part]
 
   [/part]
 
  [/story]
 
  [/story]
 
 
  #enddef
 
  #enddef
 
+
<br>
 
  #define '''AEC_STORY02'''
 
  #define '''AEC_STORY02'''
 
 
  [story]
 
  [story]
 
   [part]
 
   [part]
Line 477: Line 465:
 
   [/part]
 
   [/part]
 
  [/story]
 
  [/story]
 
 
  #enddef
 
  #enddef
 
+
<br>
 
 
 
  #define '''AEC_STORY03'''
 
  #define '''AEC_STORY03'''
 
  #Placeholder macro; no extra plot exposition for this scenario.
 
  #Placeholder macro; no extra plot exposition for this scenario.
 
  #enddef
 
  #enddef
 
+
<br>
 
 
 
  #define '''AEC_STORY04'''
 
  #define '''AEC_STORY04'''
 
 
  [story]
 
  [story]
 
   [part]
 
   [part]
Line 495: Line 479:
 
   [/part]
 
   [/part]
 
  [/story]
 
  [/story]
 
 
  #enddef
 
  #enddef
  
'''Usage:''' Copy-and-paste this into the story.cfg file, and alter the
+
'''Usage:''' Copy-and-paste this into the ''story.cfg'' file, and alter the
 
music, text and background image for each stage of the campaign. Each block
 
music, text and background image for each stage of the campaign. Each block
 
of story text should be about 2-4 lines. You can have more background text
 
of story text should be about 2-4 lines. You can have more background text
Line 506: Line 489:
 
customise them.
 
customise them.
  
Music is optional. If you don't want any music delete the 'music=&hellip;'
+
Music is optional. If you don't want any music delete the ''music=&hellip;''
 
lines.
 
lines.
  
 
On Linux the standard Wesnoth music available is in
 
On Linux the standard Wesnoth music available is in
/usr/local/share/wesnoth/music/
+
''/usr/local/share/wesnoth/music/''
 +
 
 
In Windows, the music will be in [need correct information; may vary from
 
In Windows, the music will be in [need correct information; may vary from
 
version to version]
 
version to version]
 +
 
On the Mac, the music will be in [need correct information; may vary from
 
On the Mac, the music will be in [need correct information; may vary from
 
version to version]
 
version to version]
Line 518: Line 503:
 
Background images are optional but encouraged. If no image filename is
 
Background images are optional but encouraged. If no image filename is
 
supplied, the text appears against a black screen, which is rather dull. If
 
supplied, the text appears against a black screen, which is rather dull. If
you don't have any suitable images delete the 'background=&hellip;' lines.
+
you don't have any suitable images delete the ''background=&hellip;'' lines.
  
  
 
=== route.cfg ===
 
=== route.cfg ===
  
The route.cfg file allows you to track your heroes' progress across a
+
The ''route.cfg'' file allows you to track your heroes' progress across a
 
campaign map. You don't have to have a campaign map at all, of course, but
 
campaign map. You don't have to have a campaign map at all, of course, but
they are commonly used.
+
they are widely-used in many Wesnoth campaigns.
  
 
  #define '''AEC_ROUTE01'''
 
  #define '''AEC_ROUTE01'''
 
 
  [story]
 
  [story]
 
   [part]
 
   [part]
Line 541: Line 525:
 
   [/part]
 
   [/part]
 
  [/story]
 
  [/story]
 
 
  #enddef
 
  #enddef
 
+
<br>
 
 
 
  #define '''AEC_ROUTE02'''
 
  #define '''AEC_ROUTE02'''
 
 
  [story]
 
  [story]
 
   [part]
 
   [part]
Line 561: Line 542:
 
   [/part]
 
   [/part]
 
  [/story]
 
  [/story]
 
 
  #enddef
 
  #enddef
  
 
'''Usage:''' Copy-and-paste this into the route.cfg file, and alter the
 
'''Usage:''' Copy-and-paste this into the route.cfg file, and alter the
background, DOT and CROSS commands to suit the map. Make extra copies of
+
background, ''DOT'' and ''CROSS'' commands to suit the map. Make extra
each section from #define to #enddef and renumber them for scenarios 03 and
+
copies of each section from ''#define'' to ''#enddef'' and renumber them for
onwards. 'show_title=yes' is optional, and shows the campaign title. You can
+
scenarios 03 and onwards. ''show_title=yes'' is optional, and shows the
delete this line if you don't want the title to appear.
+
campaign title. You can delete this line if you don't want the title to
 +
appear.
  
 
'''Tip:''' The distance between dots is measured in pixels. 30-60 pixels
 
'''Tip:''' The distance between dots is measured in pixels. 30-60 pixels
Line 581: Line 562:
 
=== Scenarios ===
 
=== Scenarios ===
  
Note: This template refers to macros defined in the example macro files
+
'''Note:''' This template refers to macros defined in the example macro
given above, utils.cfg, deaths.cfg, story.cfg and route.cfg. That's why you
+
files given above, ''utils.cfg'', ''deaths.cfg'', ''story.cfg'' and
have to set up those files first. To use this template, make copies of it as
+
''route.cfg''. That's why you have to set up those files first. To use this
01_First_Scenario.cfg, 02_Second_Scenario.cfg and so on for each scenario
+
template, make copies of it as ''01_First_Scenario.cfg'',
you have planned, and store them in the /Example_Campaign/scenarios/ folder.
+
''02_Second_Scenario.cfg'' and so on for each scenario you have planned,
 +
store them in the ''/Example_Campaign/scenarios/'' folder, then customise
 +
each one in turn.
  
 
  [scenario]
 
  [scenario]
Line 591: Line 574:
 
  id='''01_First_Scenario'''
 
  id='''01_First_Scenario'''
 
  next_scenario='''02_Second_Scenario'''
 
  next_scenario='''02_Second_Scenario'''
 
+
<br>
 
  {MAP '''01_First_Scenario.map'''}
 
  {MAP '''01_First_Scenario.map'''}
 
  {SCENARIO_MUSIC "gameplay01.ogg"}
 
  {SCENARIO_MUSIC "gameplay01.ogg"}
 
  {TURNS '''20 18 15'''}
 
  {TURNS '''20 18 15'''}
 
+
<br>
 
  {MORNING}
 
  {MORNING}
 
  {AFTERNOON}
 
  {AFTERNOON}
Line 602: Line 585:
 
  {SECOND_WATCH}
 
  {SECOND_WATCH}
 
  {DAWN}
 
  {DAWN}
 
+
<br>
 
  victory_when_enemies_defeated=yes
 
  victory_when_enemies_defeated=yes
 
  disallow_recall=no
 
  disallow_recall=no
 
+
<br>
 
  {'''AEC_STORY_01'''}
 
  {'''AEC_STORY_01'''}
 
  {'''AEC_ROUTE_01'''}
 
  {'''AEC_ROUTE_01'''}
 
+
<br>
 
   [side]
 
   [side]
 
   side=1
 
   side=1
Line 619: Line 602:
 
   canrecruit=yes
 
   canrecruit=yes
 
   recruit='''Archer,Bowman,Chocobone'''
 
   recruit='''Archer,Bowman,Chocobone'''
 +
  {GOLD '''150 125 100'''}
 
   [/side]
 
   [/side]
 
+
<br>
 
   [side]
 
   [side]
 
   side=2
 
   side=2
Line 630: Line 614:
 
   {GOLD '''150 200 250'''}
 
   {GOLD '''150 200 250'''}
 
   [/side]
 
   [/side]
 
+
<br>
 
   {'''AEC_DEATHS'''}
 
   {'''AEC_DEATHS'''}
 
+
<br>
 
   [event]
 
   [event]
 
   name=start
 
   name=start
Line 662: Line 646:
 
     [/objectives]
 
     [/objectives]
 
   [/event]
 
   [/event]
 
+
<br>
 
   [event]
 
   [event]
 
   name=
 
   name=
Line 672: Line 656:
 
     [/message]
 
     [/message]
 
   [/event]
 
   [/event]
 
+
<br>
 
  [/scenario]
 
  [/scenario]
  
Line 684: Line 668:
 
  name= _ ""
 
  name= _ ""
 
  image=
 
  image=
 
+
<br>
 
  race=
 
  race=
 
  hitpoints=
 
  hitpoints=
Line 691: Line 675:
 
  alignment=
 
  alignment=
 
  ability=null
 
  ability=null
 
+
<br>
 
  experience=500
 
  experience=500
 
  advanceto=null
 
  advanceto=null
 
  level=
 
  level=
 
  cost=
 
  cost=
 
+
<br>
 
  usage=## AI usage: values are 'scout', 'fighter', 'archer', 'healer' and 'mixed fighter'
 
  usage=## AI usage: values are 'scout', 'fighter', 'archer', 'healer' and 'mixed fighter'
 
  unit_description= _ ""
 
  unit_description= _ ""

Revision as of 18:57, 28 January 2009

This page provides a set of blank 'templates' which can be used as a basis for user-made campaigns, scenarios, and units. You will need to have a basic understanding of WML to make best use of these resources. See ReferenceWML. You will also need to understand how to create text files on your computer and set up an appropriate directory structure for the campaign. By the time you have created a simple campaign using these templates, you should have learned enough about WML to be able to create more ambitious work on your own.

Campaigns

For a basic campaign, you need to create a set of .cfg files in the correct locations. That also means you have to create a set of correctly-named directories as well. These examples will lead you through the basic setup of a campaign called Example_Campaign. You will need to replace all occurrences of Example_Campaign with the name of your own campaign.

For everything to work reliably, the names must be exactly as shown. If there is a mismatch between any of the names, Wesnoth will not be able to find all the data it needs to run your campaign, and it will stop dead with an error. Assume that all names are case-sensitive, and use underscores ( _ ) for spaces between words. Avoid accented characters as well. If you do not, you may find that your campaign only works properly for other people using the same operating system as you.

For Linux users, all paths are relative to /home/username/.wesnoth/data/campaigns/, where username will be the currently logged-in user. The game has been organised so that you can keep your own data separate from the main Wesnoth data, which means your custom campaigns will not interfere with the workings of the rest of the game, and ensures that you should never need to alter anything inside the main Wesnoth folder (usually /usr/local/share/wesnoth or similar).

For Mac users, [need correct information; may vary from version to version]

For Windows users, [need correct information; may vary from version to version]


Basic file creation

To make a campaign, you need to create a set of files and directories, as follows:

  • A blank text file: /Example_Campaign.cfg
  • A campaign folder: /Example_Campaign/
  • A scenario folder: /Example_Campaign/scenarios/
  • A maps folder: /Example_Campaign/maps/
  • A units folder: /Example_Campaign/units/
  • An images folder: /Example_Campaign/images/
  • A utilities (macros) folder: /Example_Campaign/utils/
  • At least one scenario file: /Example_Campaign/scenarios/01_First_Scenario.cfg
  • As many maps as scenarios: /Example_Campaign/maps/01_First_Scenario.map
  • Inside the utils folder, a blank text file: /utils.cfg
  • Inside the utils folder, a blank text file: /deaths.cfg
  • Inside the utils folder, a blank text file: /route.cfg
  • Inside the utils folder, a blank text file: /story.cfg


Tip: Number your scenarios as the first part of their filenames. This makes it easier to tell what order they will be used in. If your scenarios branch (meaning a player will either play scenario A or scenario B, but not both), label the alternatives something like 03a_First_Branch.cfg, 03b_Second_Branch.cfg and so on. For a basic campaign, we advise you not to use scenario branching unless you're already a confident WML coder.

Tip: Use the same numbering scheme for your maps as well, although if you want to name the maps differently from the corresponding scenario, that's fine. For example, you might have a scenario called 01_Kidnap_Attempt.cfg, while the associated map is called 01_The_Royal_Park.map.

While you may not need custom folders for, say, units or campaign-specific graphics, it does no harm to set them up in advance and leave them empty, so we suggest you create them anyway.

It is important that you place all the parts of your campaign in the right places and that the folders are named correctly, because Wesnoth will look for these folders to find your scenarios, images etc. If you use a different folder arrangement of your own (for example if you store all your macros in a /macros/ directory) then you will have to adjust the example code accordingly.

Tip: Choose an abbreviation for your campaign that doesn't clash with the names of any other campaign. For example, Heir to the Throne is commonly abbreviated HTTT. If your campaign is called An Example Campaign, use AEC. This is useful because you can then prepend AEC to your campaign-specific macros and avoid accidental name clashes with WML code from other campaigns.


Example_Campaign.cfg, [Campaign] section

The Example_Campaign.cfg file has two parts. The first part determines the available difficulty settings and difficulty descriptions for your campaign. Without this data, your campaign will not appear in the Wesnoth menu, and you won't be able to select it for playing. The difficulty settings are stored between a [campaign] and a [/campaign] tag as shown below. The parts marked in bold are the bits you will need to customise:

[campaign]
name= _ "An Example Campaign"
id=EXAMPLE_CAMPAIGN
define=EXAMPLE_CAMPAIGN
first_scenario=First_Scenario

difficulties=EASY,NORMAL,HARD difficulty_descriptions={MENU_IMG_TXT2 Easy_Image.png _"Easy setting description" _"(Easy)"} + ";" + {MENU_IMG_TXT2 Normal_Image.png _"Normal setting description" _"(Normal)"} + ";" + {MENU_IMG_TXT2 Hard_Image.png _"Hard setting description" _"(Hard)"}
icon=Campaign_Icon.png description= _ "This is an example campaign template, all ready to be customised."
[about] title= _ "Campaign Designer" text="Your Name" [/about]
[about] title= _ "Current Maintainer" text="Your Name" [/about]
[/campaign]


Working through this block of data a few lines at a time:

name= _ "An Example Campaign"


The name of your campaign as it is displayed in the Wesnoth game. This is free-text. The name should more-or-less correspond to the name of the campaign folder, but you don't have to worry about file naming restrictions such as having to use underscores for spaces.


id=EXAMPLE_CAMPAIGN

The campaign identifier. This is used internally by the Wesnoth game.


define=EXAMPLE_CAMPAIGN

We will call this important entry the campaign name key. The #ifdef command used in the next section must exactly match whatever you define here.


first_scenario=First_Scenario

The scenario identifier for the first scenario. This must exactly match the scenario ID in the relevant scenario file. It's helpful (but not compulsory) to have the scenario filename and the scenario ID match.


difficulties=EASY,NORMAL,HARD

Using three different difficulty levels is very common for Wesnoth scenarios, but you can have more or fewer if you want. For now, stick with three, and leave their names unaltered.


difficulty_descriptions={MENU_IMG_TXT2 Easy_Image.png
_"Easy setting description" _"(Easy)"} + ";"
+ {MENU_IMG_TXT2 Normal_Image.png
_"Normal setting description" _"(Normal)"} + ";"
+ {MENU_IMG_TXT2 Hard_Image.png
_"Hard setting description" _"(Hard)"}

There are six different things you can customise here. The Easy, Normal and Hard setting descriptions are usually set to an atmospheric name for the corresponding difficulty level. For example, you might use Scout for the easiest setting, Warrior for the middle setting, and General for the hardest setting. As a rough guide, you should limit yourself to 1-3 words for each difficulty description. The Easy_Image.png, Normal_Image.png and Hard_Image.png refer to custom graphics for each difficulty level. Normally you would save these in the /Example_Campaign/images/ folder. You can also use any standard Wesnoth graphic. For example, if you wanted to use the image of an orcish archer for one of the difficulty settings, you would give the filename as units/orcs/archer.png


icon=Campaign_Icon.png

A custom campaign icon is optional. If you want to use a standard Wesnoth image, provide the path from the main Wesnoth images directory. For example, items/monolith3.png. Otherwise Wesnoth will look in the /Example_Campaign/images/ folder, in this example for a png file called Campaign_Icon.png.


description= _ "This is an example campaign template, all ready to be
customised."

The campaign description is also free-text. This is a chance to give a quick summary of what your campaign is about. 2-3 lines of text is about the right length.


  [about]
    title= _ "Campaign Designer"
    text="Your Name"
  [/about]

[about] title= _ "Current Maintainer" text="Your Name" [/about]

These bits are optional, but if you're planning to share the campaign with others, it's helpful to have some information about who you are. You might also want to credit the people who have helped you with artwork, debugging, or lots of other things, but at the minimum you should fill in your name as the original campaign designer and presumably as the current maintainer too.

Having filled in and customised all of this data, you have set up a workable skeleton campaign structure. There are extra pieces of data that could be inserted into the campaign section, but the basic setup described here is enough to be going on with. Once you are ready to be more ambitions, see CampaignWML for details on other tags and customisation that could be of use.


Example_Campaign.cfg, #define section

When Wesnoth starts up, it scans for all available campaign files. But loading all the images, macros, units etc. from all available campaigns might take a very long time and might cause errors, so when Wesnoth first starts it only reads the data stored between the [campaign] and [/campaign] tags.

Remember the line define=EXAMPLE_CAMPAIGN, which we highlighted as being important? When a particular campaign is selected by the player, Wesnoth starts loading all the rest of the data for that particular campaign. But for Wesnoth to do this, the campaign name key and the campaign data must match up correctly. Assuming they do, all the scenario code found by Wesnoth matching the campaign name key will be run. And that is what the lines of code below are for. As before, you will need to customise all the bits marked in bold:

#ifdef EXAMPLE_CAMPAIGN

[binary_path] path=data/campaigns/Example_Campaign [/binary_path]
# Load campaign utilities first {@campaigns/Example_Campaign/utils}
# Add custom units [+units] {@campaigns/Example_Campaign/units} [/units]
# Add scenarios {@campaigns/Example_Campagn/scenarios}
#endif


What do these lines of data do?


#ifdef EXAMPLE_CAMPAIGN

This must match the define=EXAMPLE_CAMPAIGN from the campaign section.


[binary_path]
path=data/campaigns/Example_Campaign
[/binary_path]

The [binary_path] tag tells Wesnoth where the images/, units/, scenarios/, maps/ and utils/ folders are.


# Load campaign utilities first

This line is just a free-text comment. Note that in WML, the order in which we load things matters. It's usually a good idea to load campaign macros and utilities as soon as possible. By loading these utilities before the units and scenarios, we know that our custom utilities are available for use in our unit and scenario definitions. Trying to load scenario resources in the wrong order is a common cause of problems when writing campaigns. If for some reason you need to load things in a different order to make your campaign work, adjust the warning accordingly.


{@campaigns/Example_Campaign/utils}

This line loads all the campaign macros and utilities.


# Add custom units
[+units]
{@campaigns/Example_Campaign/units}
[/units]

These lines load all the custom units for the campaign. (# Add custom units is just another free-text comment.)


# Add scenarios
{@campaigns/Example_Campaign/scenarios}

Another comment, then a line that tells Wesnoth where to find all the campaign scenarios.


#endif

The #ifdef at the start of this section is a special multi-line instruction which must be closed using an #endif tag.


utils.cfg

Next you need a file called /Example_Campaign/utils/utils.cfg. If you created the utils folder and utils.cfg file in section 1, a blank file with the correct name will already be set up in the correct location. Otherwise, create it now.

The purpose of the utils.cfg file is to act as a repository for any campaign-specific macros you create. Other useful macros can be stored here as well. How you organise them is up to you – you can store them all in the utils.cfg file, or save each one in its own .cfg file. As long as you save all you macros inside the utils directory, everything should work as expected.

Here are some sample macros that are widely-used in many campaigns:


Maps

# A simple map-listing macro
# Usage: map={MAP scenario_name.map}

#define MAP MAP_NAME map_data="{@campaigns/CAMPAIGN_NAME/maps/{MAP_NAME}}" #enddef

Usage: Just copy-and-paste these five lines of text untouched into the utils.cfg file. When you want to use this macro, you call it in your scenario.cfg files, by inserting a line such as map={MAP 01_First_Scenario.map} or map={MAP 02a_Second_Scenario_Branch_A.map} customising as appropriate to your campaign.


deaths.cfg

This is a macro that will trigger on the death of major campaign characters, including the heroes. If you only need a few dying speeches, you could just store the deaths macro inside utils.cfg. If you have more than about four, or if you plan for characters to use different dying speeches in different scenarios, it's probably better to store the deaths macro separately, as it could get rather long.

#define AEC_DEATHS

[event] name=die [filter] description="Hero Name" [/filter] [message] description="Hero Name" message= _ "Hero's final words" [/message] [endlevel] result=defeat [/endlevel] [/event]
[event] name=die [filter] description="Sidekick Name" [/filter] [message] description="Sidekick Name" message= _ "Sidekick's final words" [/message] [endlevel] result=defeat [/endlevel] [/event]
[event] name=die [filter] description="Enemy Name" [/filter] [message] description="Enemy Name" message= _ "Enemy's final words" [/message] [endlevel] result=victory [/endlevel] [/event]
#enddef

Usage: Copy-and-paste this into the deaths.cfg file, and alter the names and final words for each character. If the unit's dying means game over for the player, include the section of text that says

[endlevel]
result=defeat
[/endlevel]

otherwise delete it.

If the unit's dying means an immediate victory in that scenario, include the section of text that says

[endlevel]
result=victory
[/endlevel]

If you have additional units who need to speak some final words, just make extra copies of the appropriate [event] … [/event] section and customise them to suit.


story.cfg

The story.cfg file allows you to collect together all the background plot for the campaign in one place. You can include this data inside the individual scenario files, but it's better coding practice to separate things out a bit. You can then manage the entire campaign plot in one place rather than having to scan through a dozen scenario files.


#define AEC_STORY01
[story]
  [part]
  music=gameplay01.ogg
  story= _ "The background story, part one."
  background=Background_Image01.png
  [/part]
  [part]
  music=gameplay02.ogg
  story= _ "The background story, part two."
  background=Background_Image02.png
  [/part]
[/story]
#enddef

#define AEC_STORY02 [story] [part] music=gameplay01.ogg story= _ "The background story, part three." background=Background_Image03.png [/part] [/story] #enddef
#define AEC_STORY03 #Placeholder macro; no extra plot exposition for this scenario. #enddef
#define AEC_STORY04 [story] [part] music=gameplay03.ogg story= _ "An unexpected twist halfway through the campaign." background=Background_Image04.png [/part] [/story] #enddef

Usage: Copy-and-paste this into the story.cfg file, and alter the music, text and background image for each stage of the campaign. Each block of story text should be about 2-4 lines. You can have more background text at the very start of the campaign, but don't insert two or three paragraphs of prose between every scenario. Very few people will read it. When you need extra plot sections, just make extra copies of the appropriate parts and customise them.

Music is optional. If you don't want any music delete the music=… lines.

On Linux the standard Wesnoth music available is in /usr/local/share/wesnoth/music/

In Windows, the music will be in [need correct information; may vary from version to version]

On the Mac, the music will be in [need correct information; may vary from version to version]

Background images are optional but encouraged. If no image filename is supplied, the text appears against a black screen, which is rather dull. If you don't have any suitable images delete the background=… lines.


route.cfg

The route.cfg file allows you to track your heroes' progress across a campaign map. You don't have to have a campaign map at all, of course, but they are widely-used in many Wesnoth campaigns.

#define AEC_ROUTE01
[story]
  [part]
  background=Campaign_Map.png
  show_title=yes
  {DOT 100 150}
  {DOT 150 150}
  {DOT 200 150}
  {DOT 250 150}
  {DOT 250 200}
  {CROSS 250 250}
  [/part]
[/story]
#enddef

#define AEC_ROUTE02 [story] [part] background=Campaign_Map.png show_title=yes {DOT 280 290} {DOT 310 330} {DOT 340 370} {DOT 370 410} {DOT 400 450} {DOT 430 490} {DOT 460 530} {CROSS 490 570} [/part] [/story] #enddef

Usage: Copy-and-paste this into the route.cfg file, and alter the background, DOT and CROSS commands to suit the map. Make extra copies of each section from #define to #enddef and renumber them for scenarios 03 and onwards. show_title=yes is optional, and shows the campaign title. You can delete this line if you don't want the title to appear.

Tip: The distance between dots is measured in pixels. 30-60 pixels between dots is about right. The bigger the gap, the faster the heroes are assumed to be moving, so if they're moving at constant speed try to keep the distance between dots more or less constant. That's a bit more complicated if they're moving at an angle other than exactly horizontal or exactly vertical. As a rule of thumb, 50 dots horizontally comes to 35 + 35 at 45° when moving diagonally.


Scenarios

Note: This template refers to macros defined in the example macro files given above, utils.cfg, deaths.cfg, story.cfg and route.cfg. That's why you have to set up those files first. To use this template, make copies of it as 01_First_Scenario.cfg, 02_Second_Scenario.cfg and so on for each scenario you have planned, store them in the /Example_Campaign/scenarios/ folder, then customise each one in turn.

[scenario]
name= _ "The First Scenario"
id=01_First_Scenario
next_scenario=02_Second_Scenario

{MAP 01_First_Scenario.map} {SCENARIO_MUSIC "gameplay01.ogg"} {TURNS 20 18 15}
{MORNING} {AFTERNOON} {DUSK} {FIRST_WATCH} {SECOND_WATCH} {DAWN}
victory_when_enemies_defeated=yes disallow_recall=no
{AEC_STORY_01} {AEC_ROUTE_01}
[side] side=1 controller=human fog=no shroud=no team_name=good description=Hero Name type=Spearman canrecruit=yes recruit=Archer,Bowman,Chocobone {GOLD 150 125 100} [/side]
[side] side=2 team_name=evil description=Enemy Name type=Horseman canrecruit=yes recruit=Draug,Elvish Archer,Fencer {GOLD 150 200 250} [/side]
{AEC_DEATHS}
[event] name=start [recall] description= [/recall] [message] description= message= _ "" [/message] [objectives] side=1 [objective] description= _ "Victory Condition" condition=win [/objective] [objective] description= _ "Death of Hero" condition=lose [/objective] [objective] description= _ "Death of Sidekick" condition=lose [/objective] [objective] description= _ "Turns run out" condition=lose [/objective] [/objectives] [/event]
[event] name= [filter] [/filter] [message] description= message= _ "" [/message] [/event]
[/scenario]



Units

[unit]
id=
name= _ ""
image=

race= hitpoints= movement_type= movement= alignment= ability=null
experience=500 advanceto=null level= cost=
usage=## AI usage: values are 'scout', 'fighter', 'archer', 'healer' and 'mixed fighter' unit_description= _ "" get_hit_sound=groan.wav [attack] name= _ "" type= damage= number= special=null [frame] begin=-100 end=100 image= [/frame] [sound] time=-200 sound= [/sound] [/attack] [attack] name= _ "" type= range=long damage= number= special=null [sound] time=-200 sound= [/sound] [missile_frame] begin=-100 end=0 image= image_diagonal= [/missile_frame] [/attack] [/unit]

See Also