Changeset 38 in tmcsimulator-scriptbuilder for trunk/src/scriptbuilder/structures/SimulationScript.java
- Timestamp:
- 08/03/2017 04:30:19 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/scriptbuilder/structures/SimulationScript.java
r30 r38 19 19 import scriptbuilder.structures.ScriptIncident.IncidentFocusedEvent; 20 20 import scriptbuilder.structures.ScriptIncident.SliceChangedEvent; 21 import scriptbuilder.structures.units.Unit; 21 22 22 23 /** … … 56 57 public List<ScriptIncident> incidents; 57 58 59 /** 60 * The units which participate in Unit events. 61 */ 62 public List<Unit> units; 63 58 64 //Somewhere in the code, something assumes that the list of incidents 59 65 //contains exactly 10 items. Until I can find and un-break that, this will do. … … 80 86 sh = new MyScriptHandler(this); 81 87 incidents = new ArrayList<ScriptIncident>(); 88 units = new ArrayList<Unit>(); 82 89 numberOfIncidents = 0; 83 90 84 // Create the media event85 /*incidents.add(new ScriptIncident(incidentColors[0], 100, "Media",86 "An incident for the media in CAD.", 10800, this));87 numberOfIncidents++;88 // Create the "other" event89 incidents.add(new ScriptIncident(incidentColors[9], 999, "Other",90 "An incident for small-scale events, false events, "91 + "and noise. All events added to this incident will "92 + "receive a randomly generated incident number.",93 10800, this));94 numberOfIncidents++;*/95 91 //Backfill with null incidents 96 92 for (int i = numberOfIncidents; i < INCIDENT_FILL_COUNT; i++) … … 98 94 incidents.add(null); 99 95 } 100 /*101 Add some demo events102 incidents.add(new ScriptIncident(incidentColors[1], 174, "Blueberry Truck",103 "Blueberry truck crashed on the freeway.", 8800, this));104 numberOfIncidents++;105 incidents.add(new ScriptIncident(incidentColors[2], 175, "Construction Crash",106 "Crash at construction site on Red Road.", 6800, this));107 numberOfIncidents++;108 incidents.add(new ScriptIncident(incidentColors[3], 176, "Car Freeway Flip",109 "Car flipped across the lane divider on the freeway.", 7200, this));110 numberOfIncidents++;111 incidents.add(new ScriptIncident(incidentColors[4], 177, "Two Lane Crash",112 "Crash taking two lanes on Tree Road.", 4200, this));113 numberOfIncidents++;114 incidents.add(new ScriptIncident(incidentColors[5], 178, "Stalled Truck",115 "Truck stalled on the freeway.", 2800, this));116 numberOfIncidents++;117 incidents.add(new ScriptIncident(incidentColors[6], 179, "Tomato Truck Spill",118 "Tomato trucked spilt tomatos all over the freeway.", 3200, this));119 incidents.add(new ScriptIncident(incidentColors[7], 180, "Crash at Intersection",120 "Crash at the intersection of Tree Road and Red Road.", 4300, this));121 incidents.add(new ScriptIncident(incidentColors[8], 181, "Bomb Threat",122 "Bomb threat and Road X.", 6000, this));123 incidents.add(null);124 incidents.add(null);125 incidents.add(null);126 Random rng = new Random();127 ScriptEventType[] eventTypes = ScriptEventType.values();128 if (numberOfIncidents > 0)129 {130 for (int i = 0; i < 300; i++)131 {132 int n = rng.nextInt();133 int s = rng.nextInt();134 int e = rng.nextInt();135 if (n < 0)136 {137 n *= -1;138 }139 if (s < 0)140 {141 s *= -1;142 }143 if (e < 0)144 {145 e *= -1;146 }147 incidents.get(n % numberOfIncidents).slices.get(s % (incidents.get(n % numberOfIncidents).slices.size())).addEvent(new ScriptEvent(eventTypes[e % eventTypes.length]));148 }149 incidents.get(1).setOffset(200);150 incidents.get(2).setOffset(3400);151 incidents.get(3).setOffset(1400);152 incidents.get(4).setOffset(4400);153 incidents.get(5).setOffset(1400);154 incidents.get(6).setOffset(7600);155 incidents.get(7).setOffset(2400);156 incidents.get(8).setOffset(4800);157 }158 */159 96 } 160 97 … … 207 144 208 145 Vector<ScriptIncident> inc = sh.getIncidents(); 209 146 units = sh.getUnits(); 210 147 for (ScriptIncident sci : inc) 211 148 { … … 246 183 public String toXML() 247 184 { 185 ArrayList<TimeSlice> slices = allSlices(); 248 186 String output = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n"; 249 output += "<!DOCTYPE TMC_SCRIPT SYSTEM \"script.dtd\">"; 250 ArrayList<TimeSlice> slices = allSlices(); 187 output += "<!DOCTYPE TMC_SCRIPT SYSTEM \"script.dtd\">\n"; 251 188 output += openTag(ELEMENT.TMC_SCRIPT.tag + " title=\"" + this.title + "\""); 189 190 if (units.size() > 0) 191 { 192 output += openTag(ELEMENT.SCRIPT_DATA.tag); 193 for (Unit unit : units) 194 { 195 output += unit.toXML(); 196 } 197 output += closeTag(ELEMENT.SCRIPT_DATA.tag); 198 } 252 199 for (TimeSlice slice : slices) 253 200 { … … 261 208 public String openTag(String s) 262 209 { 263 return "<" + s + "> \n";210 return "<" + s + ">"; 264 211 } 265 212 … … 291 238 for (ScriptIncident inc : incidents) 292 239 { 293 240 294 241 if (inc != null && inc.slices.get(i) != null) 295 242 {
Note: See TracChangeset
for help on using the changeset viewer.
