Configuration Files

From SemanticLab

Jump to: navigation, search

This document describes how the Mölltal Manager initializes game plug-ins by using the plugin.xml.


Class Definition

After the game's start, the Manager class scans the plug-in directories for the plug-in configuration file (plugin.xml) and runs the initialization code of all GameObjects specified in this file.

The plugin.xml contains the following structure:

  1. a standard XML header
  2. the GameObjects root element encapsulating all other elements
  3. a Plugin element containing meta data such as
    • the project name (Name)
    • the plug-in's authors (Author)
    • the project group (Group) which consists of the project's year and either the letter 's' (summer term) or 'w' (winter term).

The following example illustrates the syntax used in the configuration file by creating an instance of the class at.ac.wu.moelltal.plugin.examples.Batman and calling its init method with a ConfigValue object which contains the following four entries: xpos=1, ypos=1, name=Batman, image=fatbat2.png.

<?xml version='1.0' encoding='utf-8'?> 
 
<GameObjects xmlns="http://www.ai.wu.ac.at/moelltal/2007w#">
   <Plugin>
      <Name>Examples</Name>
      <Author>Albert Weichselbraun, Hans Mitlöhner</Author>
      <Group>2007s</Group>
   </Plugin> 
   <!-- batman -->
   <GameObject class="at.ac.wu.moelltal.plugin.examples.Batman">
      <config name="xpos" value="1" />
      <config name="ypos" value="1" />
      <config name="name" value="Batman" />
      <config name="image" value="fatbat2.png" />
   </GameObject>
</GameObjects>

Based on the plugin.xml introduced above the Manager creates the class at.ac.wu.moelltal.plugin.examples.Batman and calls its init method.

package at.ac.wu.moelltal.plugin.examples;
 
public class Batman extends GameCharacter {
 
  /** initialize Batman Player object */
  public void init(Manager m, ConfigValue v) {
    // set name, portrait and image based on the configuration
    // values in plugin.xml
    setName( v.getStringValue("name"));
    setPortrait( v.getStringValue("image"));
    setImage(v.getStringValue("image"));
 
    // set the objects position in the gamefield 
    Tile t = m.getArea().getTile( v.getIntValue("xpos"), v.getIntValue("ypos"));
    setLoc(t);
 
    // set this object to be a npc (non player character)
    setPlayerControlled(false);
 
    // register the object with the manager
    m.registerActor( this );	
}

You may specify arbitrary classes for initialization in your GameObject definitions.


Examples

The example below creates two orcs with different start positions and names (two instances of the same class but with different configuration parameters).

<?xml version='1.0' encoding='utf-8'?> 
 
<GameObjects xmlns="http://www.ai.wu-wien.ac.at/moelltal/2007w#">
   <!-- first orc -->
   <GameObject class="at.ac.wu.moelltal.plugin.examples.Orc">
      <config name="xpos" value="7" />
      <config name="ypos" value="7" />
      <config name="name" value="A little Orc" />
      <config name="image" value="orc_stage1.png" />
      <config name="image2" value="orc_stage2.png" />
   </GameObject>
 
   <!-- second orc -->
   <GameObject class="at.ac.wu.moelltal.plugin.examples.Orc">
      <config name="xpos" value="2" />
      <config name="ypos" value="3" />
      <config name="name" value="Klog" />
      <config name="image" value="orc2.png" />
   </GameObject>
 
</GameObjects>
Personal tools