private static void PopulateNeutralTruck(XmlDocument xmlDoc, XmlNode parentNode, NeutralTruckConfig c) { // Create "NeutralTruck" node and append to parentNode XmlNode node = xmlDoc.CreateElement("NeutralTruck"); parentNode.AppendChild(node); // Add attributes AddAttribute(xmlDoc, node, "x_km", c.x_km.ToString()); AddAttribute(xmlDoc, node, "z_km", c.z_km.ToString()); AddOptionalAttribute(xmlDoc, node, "id", c.id); AddOptionalAttribute(xmlDoc, node, "sensorBeamwidth_deg", c.sensorBeamwidth_deg); // Add perception override (if specified) AddPerceptionOverride(xmlDoc, node, c); }
// Local platform category parsing private static void ParseLocal(XmlNode node, SoaConfig soaConfig) { // Go through each child node PlatformConfig newConfig = new BluePoliceConfig(0.0f, 0.0f, 0.0f, new Optional <int>(), new Optional <float>(), new Optional <float>()); // Dummy value bool newConfigValid; foreach (XmlNode c in node.ChildNodes) { newConfigValid = true; try { switch (c.Name) { case "RedDismount": { newConfig = new RedDismountConfig( GetFloatAttribute(c, "x_km", 0), 0, // No y_km field for land unit GetFloatAttribute(c, "z_km", 0), GetOptionalIntAttribute(c, "id"), GetOptionalFloatAttribute(c, "sensorBeamwidth_deg"), GetOptionalStringAttribute(c, "initialWaypoint"), GetOptionalBooleanAttribute(c, "hasWeapon"), GetOptionalFloatAttribute(c, "commsRange_km"), GetOptionalIntAttribute(c, "numStorageSlots") ); } break; case "RedTruck": { newConfig = new RedTruckConfig( GetFloatAttribute(c, "x_km", 0), 0, // No y_km field for land unit GetFloatAttribute(c, "z_km", 0), GetOptionalIntAttribute(c, "id"), GetOptionalFloatAttribute(c, "sensorBeamwidth_deg"), GetOptionalStringAttribute(c, "initialWaypoint"), GetOptionalBooleanAttribute(c, "hasWeapon"), GetOptionalBooleanAttribute(c, "hasJammer"), GetOptionalFloatAttribute(c, "commsRange_km"), GetOptionalFloatAttribute(c, "jammerRange_km"), GetOptionalIntAttribute(c, "numStorageSlots") ); } break; case "NeutralDismount": { newConfig = new NeutralDismountConfig( GetFloatAttribute(c, "x_km", 0), 0, // No y_km field for land unit GetFloatAttribute(c, "z_km", 0), GetOptionalIntAttribute(c, "id"), GetOptionalFloatAttribute(c, "sensorBeamwidth_deg") ); } break; case "NeutralTruck": { newConfig = new NeutralTruckConfig( GetFloatAttribute(c, "x_km", 0), 0, // No y_km field for land unit GetFloatAttribute(c, "z_km", 0), GetOptionalIntAttribute(c, "id"), GetOptionalFloatAttribute(c, "sensorBeamwidth_deg") ); } break; case "BluePolice": { newConfig = new BluePoliceConfig( GetFloatAttribute(c, "x_km", 0), 0, // No y_km field for land unit GetFloatAttribute(c, "z_km", 0), GetOptionalIntAttribute(c, "id"), GetOptionalFloatAttribute(c, "sensorBeamwidth_deg"), GetOptionalFloatAttribute(c, "commsRange_km") ); } break; default: newConfigValid = false; if (c.Name != "#comment") { Debug.LogWarning("SoaConfigXMLReader::ParseLocal(): Unrecognized node " + c.Name); } break; } } catch (Exception) { Debug.LogError("SoaConfigXMLReader::ParseLocal(): Error parsing " + c.Name); } // End try-catch // Handle and add the new config if it is valid if (newConfigValid) { // Parse any sensor/classifier override modalities specified foreach (XmlNode g in c.ChildNodes) { switch (g.Name) { case "Sensor": newConfig.SetSensorModalities(ParseModalities(g)); break; case "Classifier": newConfig.SetClassifierModalities(ParseModalities(g)); break; } } // Add to list of local platforms soaConfig.localPlatforms.Add(newConfig); } // End if new config valid } // End foreach }