How to create scenarios

Scenarios are created in a format called XML which is similar to HTML. You can describe pawns and obstacles that go into a scenario. This includes location, velocity, weapons, scanners, etc. Properties have default values if you don't provide a value.

The following sample defines a scenario called "Sample" with two tanks and a rock. You can have multiple scenarios defined in the same file as long as they have different ids.

<scenario class="com.loki3.cyber.server.Scenario" id="Sample">

   <add class="FollowerTank">
      <use refid="basetank">
         <where>95 95</where>
         <velocity>-0.4 -0.5</velocity>
      </use>
   </add>

   <add class="TestTank">
      <use refid="basetank">
         <where>91 5</where>
         <velocity>0 0.9</velocity>
      </use>
   </add>

   <item class="com.loki3.cyber.pawn.ObstacleRock">
      <where>40 60</where>
      <radius>7</radius>
      <segments>11</segments>
   </item>

</scenario>

In the previous example, most of the properties for the pawns are defined by an object with an id of "basetank." See inheriting properties for more details.

Defining your pawn

Properties for pawns include information about movement, energy usage, weapons and scanners.

   <size>5 10 3</size>
   <hitpoints>50</hitpoints>
   <maxspeed>2</maxspeed>
   <acceleration>0.1</acceleration>
   <angleacceleration>0.05</angleacceleration>
   <energy>
      <total>100</total>
      <pertick>0.1</pertick>
   </energy>
   <weapon class="com.loki3.cyber.pawn.WeaponTurret">
      <size>1 6 0.5</size>
      <angleacceleration>0.1</angleacceleration>
      <offset>0 0</offset>
      <hitpoints>20</hitpoints>
      <ammospeed>2</ammospeed>
      <reloadspeed>5</reloadspeed>
      <rounds>100</rounds>
      <damage>2</damage>
      <maxdistance>40</maxdistance>
      <ammoradius>0.5</ammoradius>
   </weapon>
   <weapon class="com.loki3.cyber.pawn.WeaponMineLayer">
      <size>0.5 0.5 0.5</size>
      <offset>-5.8 0</offset>
      <hitpoints>20</hitpoints>
      <rounds>10</rounds>
   </weapon>
   <scanner class="com.loki3.cyber.pawn.ScannerPerfect">
      <size>1 2 0.5</size>
      <offset>-1 1</offset>
      <hitpoints>10</hitpoints>
      <maxrange>60</maxrange>
   </scanner>

Inheriting properties

You don't have to specify every property for every object each time. Instead you can define a group of properties, give it an id and reference the properties by its id later.

<pawn id="default">
   <size>5 10 3</size>
   <hitpoints>50</hitpoints>
<pawn>

<scenario class="com.loki3.cyber.server.Scenario" id="Sample">

   <add class="FollowerTank">
      <use refid="default">
         <where>95 95</where>
         <velocity>-0.4 -0.5</velocity>
      </use>
   </add>

</scenario>

Property reference

Referencing your own code

You can easily write your own code and reference it from a scenario file. You need to make sure your Java class is public and implements the GameListener interface. Reference your class by name in the scenario file, including the package name if any.

public class MyController implements GameListener
{
	public boolean use(Pawn pawn)          { return true; }
	public void gameStarted(Pawn pawn)     {}
	public void gameTick(double tick)      {}
	public void gameEnded()                {}
}

<scenario class="com.loki3.cyber.server.Scenario" id="Sample">
   <add class="MyController">
      <use refid="basetank">
      </use>
   </add>
</scenario>

Or if you want to specify a package...

package com.my-domain;
public class MyController implements GameListener
	...

<scenario class="com.loki3.cyber.server.Scenario" id="Sample">
   <add class="com.my-domain.MyController">
      <use refid="basetank">
      </use>
   </add>
</scenario>

You can even set properties on your object through the scenario file. All you have to do is make the property public or provide a public setProperty method. The type of the property can be any of the built-in Java types (int, boolean, String, etc.) or another class that has public scoping and public properties.

public class MyController implements GameListener
{
	public int MyProperty = 5;	// provide a default
	public void setAnotherProperty(double f)
	...
}

<scenario class="com.loki3.cyber.server.Scenario" id="Sample">
   <add class="MyController">
      <use refid="basetank">
         <MyProperty>149</MyProperty>
         <AnotherProperty>3.141592</AnotherProperty>
      </use>
   </add>
</scenario>