Index: trunk/src/scriptbuilder/structures/SimulationScript.java
===================================================================
--- trunk/src/scriptbuilder/structures/SimulationScript.java	(revision 30)
+++ trunk/src/scriptbuilder/structures/SimulationScript.java	(revision 38)
@@ -19,4 +19,5 @@
 import scriptbuilder.structures.ScriptIncident.IncidentFocusedEvent;
 import scriptbuilder.structures.ScriptIncident.SliceChangedEvent;
+import scriptbuilder.structures.units.Unit;
 
 /**
@@ -56,4 +57,9 @@
     public List<ScriptIncident> incidents;
 
+    /**
+     * The units which participate in Unit events.
+     */
+    public List<Unit> units;
+
     //Somewhere in the code, something assumes that the list of incidents
     //contains exactly 10 items. Until I can find and un-break that, this will do.
@@ -80,17 +86,7 @@
         sh = new MyScriptHandler(this);
         incidents = new ArrayList<ScriptIncident>();
+        units = new ArrayList<Unit>();
         numberOfIncidents = 0;
 
-        // Create the media event
-        /*incidents.add(new ScriptIncident(incidentColors[0], 100, "Media",
-         "An incident for the media in CAD.", 10800, this));
-         numberOfIncidents++;
-         // Create the "other" event
-         incidents.add(new ScriptIncident(incidentColors[9], 999, "Other",
-         "An incident for small-scale events, false events, "
-         + "and noise.  All events added to this incident will "
-         + "receive a randomly generated incident number.",
-         10800, this));
-         numberOfIncidents++;*/
         //Backfill with null incidents
         for (int i = numberOfIncidents; i < INCIDENT_FILL_COUNT; i++)
@@ -98,63 +94,4 @@
             incidents.add(null);
         }
-        /*
-         Add some demo events
-         incidents.add(new ScriptIncident(incidentColors[1], 174, "Blueberry Truck",
-         "Blueberry truck crashed on the freeway.", 8800, this));
-         numberOfIncidents++;
-         incidents.add(new ScriptIncident(incidentColors[2], 175, "Construction Crash",
-         "Crash at construction site on Red Road.", 6800, this));
-         numberOfIncidents++;
-         incidents.add(new ScriptIncident(incidentColors[3], 176, "Car Freeway Flip",
-         "Car flipped across the lane divider on the freeway.", 7200, this));
-         numberOfIncidents++;
-         incidents.add(new ScriptIncident(incidentColors[4], 177, "Two Lane Crash",
-         "Crash taking two lanes on Tree Road.", 4200, this));
-         numberOfIncidents++;
-         incidents.add(new ScriptIncident(incidentColors[5], 178, "Stalled Truck",
-         "Truck stalled on the freeway.", 2800, this));
-         numberOfIncidents++;
-         incidents.add(new ScriptIncident(incidentColors[6], 179, "Tomato Truck Spill",
-         "Tomato trucked spilt tomatos all over the freeway.", 3200, this));
-         incidents.add(new ScriptIncident(incidentColors[7], 180, "Crash at Intersection",
-         "Crash at the intersection of Tree Road and Red Road.", 4300, this));
-         incidents.add(new ScriptIncident(incidentColors[8], 181, "Bomb Threat",
-         "Bomb threat and Road X.", 6000, this));
-         incidents.add(null);
-         incidents.add(null);
-         incidents.add(null);
-         Random rng = new Random();
-         ScriptEventType[] eventTypes = ScriptEventType.values();
-         if (numberOfIncidents > 0)
-         {
-         for (int i = 0; i < 300; i++)
-         {
-         int n = rng.nextInt();
-         int s = rng.nextInt();
-         int e = rng.nextInt();
-         if (n < 0)
-         {
-         n *= -1;
-         }
-         if (s < 0)
-         {
-         s *= -1;
-         }
-         if (e < 0)
-         {
-         e *= -1;
-         }
-         incidents.get(n % numberOfIncidents).slices.get(s % (incidents.get(n % numberOfIncidents).slices.size())).addEvent(new ScriptEvent(eventTypes[e % eventTypes.length]));
-         }  
-         incidents.get(1).setOffset(200);
-         incidents.get(2).setOffset(3400);
-         incidents.get(3).setOffset(1400);
-         incidents.get(4).setOffset(4400);
-         incidents.get(5).setOffset(1400);
-         incidents.get(6).setOffset(7600);
-         incidents.get(7).setOffset(2400);
-         incidents.get(8).setOffset(4800); 
-         }
-         */
     }
 
@@ -207,5 +144,5 @@
 
             Vector<ScriptIncident> inc = sh.getIncidents();
-
+            units = sh.getUnits();
             for (ScriptIncident sci : inc)
             {
@@ -246,8 +183,18 @@
     public String toXML()
     {
+        ArrayList<TimeSlice> slices = allSlices();
         String output = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n";
-        output += "<!DOCTYPE TMC_SCRIPT SYSTEM \"script.dtd\">";
-        ArrayList<TimeSlice> slices = allSlices();
+        output += "<!DOCTYPE TMC_SCRIPT SYSTEM \"script.dtd\">\n";
         output += openTag(ELEMENT.TMC_SCRIPT.tag + " title=\"" + this.title + "\"");
+
+        if (units.size() > 0)
+        {
+            output += openTag(ELEMENT.SCRIPT_DATA.tag);
+            for (Unit unit : units)
+            {
+                output += unit.toXML();
+            }
+            output += closeTag(ELEMENT.SCRIPT_DATA.tag);
+        }
         for (TimeSlice slice : slices)
         {
@@ -261,5 +208,5 @@
     public String openTag(String s)
     {
-        return "<" + s + ">\n";
+        return "<" + s + ">";
     }
 
@@ -291,5 +238,5 @@
             for (ScriptIncident inc : incidents)
             {
-                
+
                 if (inc != null && inc.slices.get(i) != null)
                 {
